Skip to content

Generic Component Types does not work with InstanceType<typeof component> #8373

@ml1nk

Description

@ml1nk

Vue version

3.3.4

Link to minimal reproduction

https://stackblitz.com/edit/vitejs-vite-tpwnzy?file=src/App.vue

Steps to reproduce

Run "turbo typecheck" inside StackBlitz.

What is expected?

Either
ref<InstanceType<typeof WithGeneric<number>>>()
or
ref<InstanceType<typeof WithGeneric>>()
should generate correct typings.

What is actually happening?

src/App.vue:6:28 - error TS2344: Type 'typeof WithGeneric<number>' does not satisfy the constraint 'abstract new (...args: any) => any'.
  Type 'typeof WithGeneric<number>' provides no match for the signature 'new (...args: any): any'.

6 const a = ref<InstanceType<typeof WithGeneric<number>>>(); // type error
                             ~~~~~~~~~~~~~~~~~~~~~~~~~~

src/App.vue:7:28 - error TS2344: Type '<T>(__VLS_props: Options<T> & VNodeProps & AllowedComponentProps & ComponentCustomProps, __VLS_ctx?: Pick<{ props: Options<...>; expose(exposed: { ...; }): void; attrs: any; slots: {}; emit: any; }, "attrs" | ... 1 more ... | "slots"> | undefined, __VLS_setup?: { props: Options<...>; expose(exposed: { ...; }): void;...' does not satisfy the constraint 'abstract new (...args: any) => any'.
  Type '<T>(__VLS_props: Options<T> & VNodeProps & AllowedComponentProps & ComponentCustomProps, __VLS_ctx?: Pick<{ props: Options<...>; expose(exposed: { ...; }): void; attrs: any; slots: {}; emit: any; }, "attrs" | ... 1 more ... | "slots"> | undefined, __VLS_setup?: { ...; }) => VNode<...> & { ...; }' provides no match for the signature 'new (...args: any): any'.

7 const b = ref<InstanceType<typeof WithGeneric>>(); // type error
                             ~~~~~~~~~~~~~~~~~~

System Info

No response

Any additional comments?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    ❗ p4-importantPriority 4: this fixes bugs that violate documented behavior, or significantly improves perf.scope: types

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions