From: Evan You Date: Mon, 27 Mar 2023 10:28:43 +0000 (+0800) Subject: feat(types): `defineComponent()` with generics support (#7963) X-Git-Tag: v3.3.0-alpha.6~48 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d77557c4038f88a676903b379505b280a88cc774;p=thirdparty%2Fvuejs%2Fcore.git feat(types): `defineComponent()` with generics support (#7963) BREAKING CHANGE: The type of `defineComponent()` when passing in a function has changed. This overload signature is rarely used in practice and the breakage will be minimal, so repurposing it to something more useful should be worth it. close #3102 --- diff --git a/packages/dts-test/defineComponent.test-d.tsx b/packages/dts-test/defineComponent.test-d.tsx index 522b6a8daa..1b981a87cb 100644 --- a/packages/dts-test/defineComponent.test-d.tsx +++ b/packages/dts-test/defineComponent.test-d.tsx @@ -351,7 +351,7 @@ describe('type inference w/ optional props declaration', () => { }) describe('type inference w/ direct setup function', () => { - const MyComponent = defineComponent((_props: { msg: string }) => {}) + const MyComponent = defineComponent((_props: { msg: string }) => () => {}) expectType() // @ts-expect-error ; @@ -1250,10 +1250,130 @@ describe('prop starting with `on*` is broken', () => { }) }) +describe('function syntax w/ generics', () => { + const Comp = defineComponent( + // TODO: babel plugin to auto infer runtime props options from type + // similar to defineProps<{...}>() + (props: { msg: T; list: T[] }) => { + // use Composition API here like in