Skip to content

Commit

Permalink
fix: prefer infer new () => ... type for component
Browse files Browse the repository at this point in the history
close #2647
  • Loading branch information
johnsoncodehk committed Apr 21, 2023
1 parent c97ed08 commit 227bb3d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
10 changes: 6 additions & 4 deletions packages/vue-language-core/src/utils/localTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,13 @@ export type EmitEvent<F, E> =
} ? (...payload: P) => void
: unknown | '[Type Warning] Volar could not infer $emit event more than 4 overloads without DefineComponent. see https://github.com/johnsoncodehk/volar/issues/60';
export declare function asFunctionalComponent<T, K = T extends new (...args: any) => any ? InstanceType<T> : unknown>(t: T, instance?: K):
T extends () => any ? (props: {}) => ReturnType<T>
T extends new (...args: any) => any ?
K extends { $props?: infer Props, $slots?: infer Slots, $emit?: infer Emit }
? (props: Props ${vueCompilerOptions.strictTemplates ? '' : '& Record<string, unknown>'}, ctx?: { attrs?: any, expose?(exposed: K): void, slots?: Slots, emit?: Emit }) => JSX.Element & { __ctx?: typeof ctx, __props?: typeof props }
: never
: T extends () => any ? (props: {}) => ReturnType<T>
: T extends (...args: any) => any ? T
: K extends { $props?: infer Props, $slots?: infer Slots, $emit?: infer Emit }
? (props: Props ${vueCompilerOptions.strictTemplates ? '' : '& Record<string, unknown>'}, ctx?: { attrs?: any, expose?(exposed: K): void, slots?: Slots, emit?: Emit }) => JSX.Element & { __ctx?: typeof ctx, __props?: typeof props }
: (_: T & Record<string, unknown>, ctx?: any) => { __ctx?: { attrs?: unknown, expose?: unknown, slots?: unknown, emit?: unknown }, __props?: T & Record<string, unknown> }; // IntrinsicElement
: (_: T & Record<string, unknown>, ctx?: any) => { __ctx?: { attrs?: unknown, expose?: unknown, slots?: unknown, emit?: unknown }, __props?: T & Record<string, unknown> }; // IntrinsicElement
export declare function pickEvent<Emit, K, E>(emit: Emit, emitKey: K, event: E): FillingEventArg<
PickNotAny<
AsFunctionOrAny<NonNullable<E>>,
Expand Down
7 changes: 7 additions & 0 deletions packages/vue-test-workspace/vue-tsc/#2647/main.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<template>
<Foo></foo>
</template>

<script setup lang="ts">
let Foo!: ((props: { row: string }) => any) & (new () => any);
</script>

0 comments on commit 227bb3d

Please sign in to comment.