Skip to content

Commit 4d827be

Browse files
committed
fix(component-type-helpers): cannot infer Vue 3.4.20 functional component
1 parent cd3532d commit 4d827be

File tree

6 files changed

+825
-547
lines changed

6 files changed

+825
-547
lines changed

packages/component-meta/tests/index.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,7 @@ const worker = (checker: ComponentMetaChecker, withTsconfig: boolean) => describ
654654
const componentPath = path.resolve(__dirname, '../../../test-workspace/component-meta/ts-component/component.ts');
655655
const meta = checker.getComponentMeta(componentPath);
656656

657-
expect(meta.type).toEqual(TypeMeta.Function);
657+
expect(meta.type).toEqual(TypeMeta.Class);
658658

659659
const a = meta.props.find(prop =>
660660
prop.name === 'foo'
@@ -677,8 +677,8 @@ const worker = (checker: ComponentMetaChecker, withTsconfig: boolean) => describ
677677
const Foo = checker.getComponentMeta(componentPath, 'Foo');
678678
const Bar = checker.getComponentMeta(componentPath, 'Bar');
679679

680-
expect(Foo.type).toEqual(TypeMeta.Function);
681-
expect(Bar.type).toEqual(TypeMeta.Function);
680+
expect(Foo.type).toEqual(TypeMeta.Class);
681+
expect(Bar.type).toEqual(TypeMeta.Class);
682682
expect(exportNames).toEqual(['Foo', 'Bar']);
683683

684684
const a = Foo.props.find(prop =>
@@ -762,7 +762,7 @@ const worker = (checker: ComponentMetaChecker, withTsconfig: boolean) => describ
762762
const componentPath = path.resolve(__dirname, '../../../test-workspace/component-meta/ts-component/component.tsx');
763763
const meta = checker.getComponentMeta(componentPath);
764764

765-
expect(meta.type).toEqual(TypeMeta.Function);
765+
expect(meta.type).toEqual(TypeMeta.Class);
766766

767767
const a = meta.props.find(prop =>
768768
prop.name === 'foo'

packages/component-type-helpers/index.d.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,25 @@ export declare const code: string;
33
export default code;
44

55
export type ComponentType<T> =
6-
T extends new () => {} ? 1 :
6+
T extends new (...angs: any) => {} ? 1 :
77
T extends (...args: any) => any ? 2 :
88
0;
99

1010
export type ComponentProps<T> =
11-
T extends new () => { $props: infer P; } ? NonNullable<P> :
11+
T extends new (...angs: any) => { $props: infer P; } ? NonNullable<P> :
1212
T extends (props: infer P, ...args: any) => any ? P :
1313
{};
1414

1515
export type ComponentSlots<T> =
16-
T extends new () => { $slots: infer S; } ? NonNullable<S> :
16+
T extends new (...angs: any) => { $slots: infer S; } ? NonNullable<S> :
1717
T extends (props: any, ctx: { slots: infer S; attrs: any; emit: any; }, ...args: any) => any ? NonNullable<S> :
1818
{};
1919

2020
export type ComponentEmit<T> =
21-
T extends new () => { $emit: infer E; } ? NonNullable<E> :
22-
T extends (props: any, ctx: { slots: any; attrs: any; emit: infer E; }, ...args: any) => any ? NonNullable<E> :
21+
T extends new (...angs: any) => { $emit: infer E; } ? NonNullable<E> :
2322
{};
2423

2524
export type ComponentExposed<T> =
26-
T extends new () => infer E ? E :
25+
T extends new (...angs: any) => infer E ? E :
2726
T extends (props: any, ctx: any, expose: (exposed: infer E) => any, ...args: any) => any ? NonNullable<E> :
2827
{};

packages/component-type-helpers/index.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,27 @@
22

33
const code = `
44
export type ComponentType<T> =
5-
T extends new () => {} ? 1 :
5+
T extends new (...angs: any) => {} ? 1 :
66
T extends (...args: any) => any ? 2 :
77
0;
88
99
export type ComponentProps<T> =
10-
T extends new () => { $props: infer P; } ? NonNullable<P> :
10+
T extends new (...angs: any) => { $props: infer P; } ? NonNullable<P> :
1111
T extends (props: infer P, ...args: any) => any ? P :
1212
{};
1313
1414
export type ComponentSlots<T> =
15-
T extends new () => { $slots: infer S; } ? NonNullable<S> :
15+
T extends new (...angs: any) => { $slots: infer S; } ? NonNullable<S> :
1616
T extends (props: any, ctx: { slots: infer S; attrs: any; emit: any; }, ...args: any) => any ? NonNullable<S> :
1717
{};
1818
1919
export type ComponentEmit<T> =
20-
T extends new () => { $emit: infer E; } ? NonNullable<E> :
20+
T extends new (...angs: any) => { $emit: infer E; } ? NonNullable<E> :
2121
T extends (props: any, ctx: { slots: any; attrs: any; emit: infer E; }, ...args: any) => any ? NonNullable<E> :
2222
{};
2323
2424
export type ComponentExposed<T> =
25-
T extends new () => infer E ? E :
25+
T extends new (...angs: any) => infer E ? E :
2626
T extends (props: any, ctx: { expose(exposed: infer E): any; }, ...args: any) => any ? NonNullable<E> :
2727
{};
2828
`.trim();

packages/component-type-helpers/vue2.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ export {
1010
} from './index';
1111

1212
export type ComponentSlots<T> =
13-
T extends new () => { $scopedSlots: infer S; } ? NonNullable<S> :
13+
T extends new (...angs: any) => { $scopedSlots: infer S; } ? NonNullable<S> :
1414
T extends (props: any, ctx: { slots: infer S; attrs: any; emit: any; }, ...args: any) => any ? NonNullable<S> :
1515
{};

packages/tsc/tests/__snapshots__/dts.spec.ts.snap

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -585,11 +585,15 @@ exports[`vue-tsc-dts > Input: ts-component/component.ts, Output: ts-component/co
585585
exports[`vue-tsc-dts > Input: ts-component/component.tsx, Output: ts-component/component.d.ts 1`] = `undefined`;
586586
587587
exports[`vue-tsc-dts > Input: ts-named-export/component.ts, Output: ts-named-export/component.d.ts 1`] = `
588-
"export declare const Foo: (props: {
588+
"export declare const Foo: import("vue").DefineSetupFnComponent<{
589589
foo: string;
590-
} & {}) => any;
591-
export declare const Bar: (props: {
590+
}, {}, {}, {
591+
foo: string;
592+
} & {}, import("vue").PublicProps>;
593+
export declare const Bar: import("vue").DefineSetupFnComponent<{
594+
bar?: number;
595+
}, {}, {}, {
592596
bar?: number;
593-
} & {}) => any;
597+
} & {}, import("vue").PublicProps>;
594598
"
595599
`;

0 commit comments

Comments
 (0)