@@ -6,22 +6,65 @@ import {
6
6
ComponentOptionsWithObjectProps ,
7
7
ComponentOptionsMixin ,
8
8
RenderFunction ,
9
- UnwrapAsyncBindings
9
+ ComponentOptionsBase
10
10
} from './componentOptions'
11
11
import {
12
12
SetupContext ,
13
- FunctionalComponent ,
14
13
AllowedComponentProps ,
15
14
ComponentCustomProps
16
15
} from './component'
17
- import {
18
- CreateComponentPublicInstance ,
19
- ComponentPublicInstanceConstructor
20
- } from './componentPublicInstance'
21
16
import { ExtractPropTypes , ComponentPropsOptions } from './componentProps'
22
17
import { EmitsOptions } from './componentEmits'
23
18
import { isFunction } from '@vue/shared'
24
19
import { 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
25
68
26
69
// defineComponent is a utility that is primarily used for type inference
27
70
// when declaring components. Type inference is provided in the component
@@ -35,21 +78,7 @@ export function defineComponent<Props, RawBindings = object>(
35
78
props : Readonly < Props > ,
36
79
ctx : SetupContext
37
80
) => 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 >
53
82
54
83
// overload 2: object format with no props
55
84
// (uses user defined props interface)
@@ -58,11 +87,11 @@ export function defineComponent<
58
87
Props = { } ,
59
88
RawBindings = { } ,
60
89
D = { } ,
61
- C extends ComputedOptions = { } ,
62
- M extends MethodOptions = { } ,
90
+ C extends ComputedOptions = ComputedOptions ,
91
+ M extends MethodOptions = MethodOptions ,
63
92
Mixin extends ComponentOptionsMixin = ComponentOptionsMixin ,
64
93
Extends extends ComponentOptionsMixin = ComponentOptionsMixin ,
65
- E extends EmitsOptions = Record < string , any > ,
94
+ E extends EmitsOptions = EmitsOptions ,
66
95
EE extends string = string
67
96
> (
68
97
options : ComponentOptionsWithoutProps <
@@ -76,30 +105,7 @@ export function defineComponent<
76
105
E ,
77
106
EE
78
107
>
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 >
103
109
104
110
// overload 3: object format with array props declaration
105
111
// props inferred as { [key in PropNames]?: any }
@@ -126,32 +132,17 @@ export function defineComponent<
126
132
E ,
127
133
EE
128
134
>
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
+ >
155
146
156
147
// overload 4: object format with object props declaration
157
148
// see `ExtractPropTypes` in ./componentProps.ts
@@ -179,33 +170,20 @@ export function defineComponent<
179
170
E ,
180
171
EE
181
172
>
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 >
207
174
208
175
// implementation, close to no-op
209
176
export function defineComponent ( options : unknown ) {
210
177
return isFunction ( options ) ? { setup : options , name : options . name } : options
211
178
}
179
+
180
+ defineComponent ( {
181
+ async setup ( ) {
182
+ return {
183
+ a : 123
184
+ }
185
+ } ,
186
+ render ( ) {
187
+ this . a
188
+ }
189
+ } )
0 commit comments