@@ -6,22 +6,65 @@ import {
66 ComponentOptionsWithObjectProps ,
77 ComponentOptionsMixin ,
88 RenderFunction ,
9- UnwrapAsyncBindings
9+ ComponentOptionsBase
1010} from './componentOptions'
1111import {
1212 SetupContext ,
13- FunctionalComponent ,
1413 AllowedComponentProps ,
1514 ComponentCustomProps
1615} from './component'
17- import {
18- CreateComponentPublicInstance ,
19- ComponentPublicInstanceConstructor
20- } from './componentPublicInstance'
2116import { ExtractPropTypes , ComponentPropsOptions } from './componentProps'
2217import { EmitsOptions } from './componentEmits'
2318import { isFunction } from '@vue/shared'
2419import { VNodeProps } from './vnode'
20+ import {
21+ CreateComponentPublicInstance ,
22+ ComponentPublicInstanceConstructor
23+ } from './componentPublicInstance'
24+
25+ export type PublicProps = VNodeProps &
26+ AllowedComponentProps &
27+ ComponentCustomProps
28+
29+ export type DefineComponent <
30+ PropsOrPropOptions = any ,
31+ RawBindings = any ,
32+ D = any ,
33+ C extends ComputedOptions = ComputedOptions ,
34+ M extends MethodOptions = MethodOptions ,
35+ Mixin extends ComponentOptionsMixin = ComponentOptionsMixin ,
36+ Extends extends ComponentOptionsMixin = ComponentOptionsMixin ,
37+ E extends EmitsOptions = Record < string , any > ,
38+ EE extends string = string ,
39+ PP = PublicProps ,
40+ RequiredProps = Readonly < ExtractPropTypes < PropsOrPropOptions > > ,
41+ OptionalProps = Readonly < ExtractPropTypes < PropsOrPropOptions , false > >
42+ > = ComponentPublicInstanceConstructor <
43+ CreateComponentPublicInstance <
44+ OptionalProps ,
45+ RawBindings ,
46+ D ,
47+ C ,
48+ M ,
49+ Mixin ,
50+ Extends ,
51+ E ,
52+ PP & OptionalProps
53+ > &
54+ RequiredProps
55+ > &
56+ ComponentOptionsBase <
57+ RequiredProps ,
58+ RawBindings ,
59+ D ,
60+ C ,
61+ M ,
62+ Mixin ,
63+ Extends ,
64+ E ,
65+ EE
66+ > &
67+ PP
2568
2669// defineComponent is a utility that is primarily used for type inference
2770// when declaring components. Type inference is provided in the component
@@ -35,21 +78,7 @@ export function defineComponent<Props, RawBindings = object>(
3578 props : Readonly < Props > ,
3679 ctx : SetupContext
3780 ) => RawBindings | RenderFunction
38- ) : ComponentPublicInstanceConstructor <
39- CreateComponentPublicInstance <
40- Props ,
41- UnwrapAsyncBindings < RawBindings > ,
42- { } ,
43- { } ,
44- { } ,
45- { } ,
46- { } ,
47- { } ,
48- // public props
49- VNodeProps & Props & AllowedComponentProps & ComponentCustomProps
50- >
51- > &
52- FunctionalComponent < Props >
81+ ) : DefineComponent < Props , RawBindings >
5382
5483// overload 2: object format with no props
5584// (uses user defined props interface)
@@ -58,11 +87,11 @@ export function defineComponent<
5887 Props = { } ,
5988 RawBindings = { } ,
6089 D = { } ,
61- C extends ComputedOptions = { } ,
62- M extends MethodOptions = { } ,
90+ C extends ComputedOptions = ComputedOptions ,
91+ M extends MethodOptions = MethodOptions ,
6392 Mixin extends ComponentOptionsMixin = ComponentOptionsMixin ,
6493 Extends extends ComponentOptionsMixin = ComponentOptionsMixin ,
65- E extends EmitsOptions = Record < string , any > ,
94+ E extends EmitsOptions = EmitsOptions ,
6695 EE extends string = string
6796> (
6897 options : ComponentOptionsWithoutProps <
@@ -76,30 +105,7 @@ export function defineComponent<
76105 E ,
77106 EE
78107 >
79- ) : ComponentPublicInstanceConstructor <
80- CreateComponentPublicInstance <
81- Props ,
82- UnwrapAsyncBindings < RawBindings > ,
83- D ,
84- C ,
85- M ,
86- Mixin ,
87- Extends ,
88- E ,
89- VNodeProps & Props & AllowedComponentProps & ComponentCustomProps
90- >
91- > &
92- ComponentOptionsWithoutProps <
93- Props ,
94- RawBindings ,
95- D ,
96- C ,
97- M ,
98- Mixin ,
99- Extends ,
100- E ,
101- EE
102- >
108+ ) : DefineComponent < Props , RawBindings , D , C , M , Mixin , Extends , E , EE >
103109
104110// overload 3: object format with array props declaration
105111// props inferred as { [key in PropNames]?: any }
@@ -126,32 +132,17 @@ export function defineComponent<
126132 E ,
127133 EE
128134 >
129- ) : ComponentPublicInstanceConstructor <
130- // array props technically doesn't place any constraints on props in TSX before,
131- // but now we can export array props in TSX
132- CreateComponentPublicInstance <
133- Readonly < { [ key in PropNames ] ?: any } > ,
134- UnwrapAsyncBindings < RawBindings > ,
135- D ,
136- C ,
137- M ,
138- Mixin ,
139- Extends ,
140- E ,
141- AllowedComponentProps & ComponentCustomProps
142- >
143- > &
144- ComponentOptionsWithArrayProps <
145- PropNames ,
146- RawBindings ,
147- D ,
148- C ,
149- M ,
150- Mixin ,
151- Extends ,
152- E ,
153- EE
154- >
135+ ) : DefineComponent <
136+ Readonly < { [ key in PropNames ] ?: any } > ,
137+ RawBindings ,
138+ D ,
139+ C ,
140+ M ,
141+ Mixin ,
142+ Extends ,
143+ E ,
144+ EE
145+ >
155146
156147// overload 4: object format with object props declaration
157148// see `ExtractPropTypes` in ./componentProps.ts
@@ -179,33 +170,20 @@ export function defineComponent<
179170 E ,
180171 EE
181172 >
182- ) : ComponentPublicInstanceConstructor <
183- CreateComponentPublicInstance <
184- ExtractPropTypes < PropsOptions , false > ,
185- UnwrapAsyncBindings < RawBindings > ,
186- D ,
187- C ,
188- M ,
189- Mixin ,
190- Extends ,
191- E ,
192- VNodeProps & AllowedComponentProps & ComponentCustomProps
193- > &
194- Readonly < ExtractPropTypes < PropsOptions > >
195- > &
196- ComponentOptionsWithObjectProps <
197- PropsOptions ,
198- RawBindings ,
199- D ,
200- C ,
201- M ,
202- Mixin ,
203- Extends ,
204- E ,
205- EE
206- >
173+ ) : DefineComponent < PropsOptions , RawBindings , D , C , M , Mixin , Extends , E , EE >
207174
208175// implementation, close to no-op
209176export function defineComponent ( options : unknown ) {
210177 return isFunction ( options ) ? { setup : options , name : options . name } : options
211178}
179+
180+ defineComponent ( {
181+ async setup ( ) {
182+ return {
183+ a : 123
184+ }
185+ } ,
186+ render ( ) {
187+ this . a
188+ }
189+ } )
0 commit comments