Subscribe on changes!

TSX with dynamic element name results in "TS2322: Type '{ class: string; }' is not assignable to type 'ReservedProps'."

avatar
Apr 5th 2022

Version

3.2.31

Reproduction link

github.com

Steps to reproduce

Using Vue CLI create a Vue 3 + TS(X) project.

Create a component with the following where as is a string prop:

    render () {
        const Element = this.as;

        return (
            <Element class={this.styles}>
                {this.$slots.default && this.$slots.default()}
            </Element>
        );
    },

What is expected?

That we can create an element tag dynamically based on a value

What is actually happening?

TS2322: Type '{ class: string; }' is not assignable to type 'ReservedProps'.
  Property 'class' does not exist on type 'ReservedProps'.
    228 |
    229 |         return (
  > 230 |             <Element class={this.styles}>
        |                      ^^^^^
    231 |                 {this.$slots.default && this.$slots.default()}
    232 |             </Element>
    233 |         );

I also tried to use <component is={this.as}> which simply results in the literal value <component> being rendered in the DOM. Trying <Component> results in Cannot find name "Component". By the way, the SFC playground does not support TSX files.

avatar
Apr 5th 2022

Accidentally opened twice please look at #5666