Skip to content

Commit bdf557f

Browse files
committed
fix(types): retain type parameters order for public types
1 parent b117b88 commit bdf557f

File tree

5 files changed

+72
-38
lines changed

5 files changed

+72
-38
lines changed

packages/dts-test/defineComponent.test-d.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1494,9 +1494,9 @@ declare const MyButton: DefineComponent<
14941494
ComponentOptionsMixin,
14951495
EmitsOptions,
14961496
string,
1497-
{},
14981497
VNodeProps & AllowedComponentProps & ComponentCustomProps,
14991498
Readonly<ExtractPropTypes<{}>>,
1499+
{},
15001500
{}
15011501
>
15021502
;<MyButton class="x" />

packages/runtime-core/src/apiDefineComponent.ts

+52-18
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ export type PublicProps = VNodeProps &
3434
AllowedComponentProps &
3535
ComponentCustomProps
3636

37+
type ResolveProps<PropsOrPropOptions, E extends EmitsOptions> = Readonly<
38+
PropsOrPropOptions extends ComponentPropsOptions
39+
? ExtractPropTypes<PropsOrPropOptions>
40+
: PropsOrPropOptions
41+
> &
42+
({} extends E ? {} : EmitsToProps<E>)
43+
3744
export type DefineComponent<
3845
PropsOrPropOptions = {},
3946
RawBindings = {},
@@ -44,15 +51,10 @@ export type DefineComponent<
4451
Extends extends ComponentOptionsMixin = ComponentOptionsMixin,
4552
E extends EmitsOptions = {},
4653
EE extends string = string,
47-
S extends SlotsType = {},
4854
PP = PublicProps,
49-
Props = Readonly<
50-
PropsOrPropOptions extends ComponentPropsOptions
51-
? ExtractPropTypes<PropsOrPropOptions>
52-
: PropsOrPropOptions
53-
> &
54-
({} extends E ? {} : EmitsToProps<E>),
55-
Defaults = ExtractDefaultPropTypes<PropsOrPropOptions>
55+
Props = ResolveProps<PropsOrPropOptions, E>,
56+
Defaults = ExtractDefaultPropTypes<PropsOrPropOptions>,
57+
S extends SlotsType = {}
5658
> = ComponentPublicInstanceConstructor<
5759
CreateComponentPublicInstance<
5860
Props,
@@ -152,11 +154,25 @@ export function defineComponent<
152154
Extends,
153155
E,
154156
EE,
155-
S,
156157
I,
157-
II
158+
II,
159+
S
158160
>
159-
): DefineComponent<Props, RawBindings, D, C, M, Mixin, Extends, E, EE, S>
161+
): DefineComponent<
162+
Props,
163+
RawBindings,
164+
D,
165+
C,
166+
M,
167+
Mixin,
168+
Extends,
169+
E,
170+
EE,
171+
PublicProps,
172+
ResolveProps<Props, E>,
173+
ExtractDefaultPropTypes<Props>,
174+
S
175+
>
160176

161177
// overload 3: object format with array props declaration
162178
// props inferred as { [key in PropNames]?: any }
@@ -173,7 +189,8 @@ export function defineComponent<
173189
EE extends string = string,
174190
S extends SlotsType = {},
175191
I extends ComponentInjectOptions = {},
176-
II extends string = string
192+
II extends string = string,
193+
Props = Readonly<{ [key in PropNames]?: any }>
177194
>(
178195
options: ComponentOptionsWithArrayProps<
179196
PropNames,
@@ -185,12 +202,12 @@ export function defineComponent<
185202
Extends,
186203
E,
187204
EE,
188-
S,
189205
I,
190-
II
206+
II,
207+
S
191208
>
192209
): DefineComponent<
193-
Readonly<{ [key in PropNames]?: any }>,
210+
Props,
194211
RawBindings,
195212
D,
196213
C,
@@ -199,6 +216,9 @@ export function defineComponent<
199216
Extends,
200217
E,
201218
EE,
219+
PublicProps,
220+
ResolveProps<Props, E>,
221+
ExtractDefaultPropTypes<Props>,
202222
S
203223
>
204224

@@ -230,11 +250,25 @@ export function defineComponent<
230250
Extends,
231251
E,
232252
EE,
233-
S,
234253
I,
235-
II
254+
II,
255+
S
236256
>
237-
): DefineComponent<PropsOptions, RawBindings, D, C, M, Mixin, Extends, E, EE, S>
257+
): DefineComponent<
258+
PropsOptions,
259+
RawBindings,
260+
D,
261+
C,
262+
M,
263+
Mixin,
264+
Extends,
265+
E,
266+
EE,
267+
PublicProps,
268+
ResolveProps<PropsOptions, E>,
269+
ExtractDefaultPropTypes<PropsOptions>,
270+
S
271+
>
238272

239273
// implementation, close to no-op
240274
export function defineComponent(

packages/runtime-core/src/componentOptions.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -219,9 +219,9 @@ export type ComponentOptionsWithoutProps<
219219
Extends extends ComponentOptionsMixin = ComponentOptionsMixin,
220220
E extends EmitsOptions = EmitsOptions,
221221
EE extends string = string,
222-
S extends SlotsType = {},
223222
I extends ComponentInjectOptions = {},
224223
II extends string = string,
224+
S extends SlotsType = {},
225225
PE = Props & EmitsToProps<E>
226226
> = ComponentOptionsBase<
227227
PE,
@@ -267,9 +267,9 @@ export type ComponentOptionsWithArrayProps<
267267
Extends extends ComponentOptionsMixin = ComponentOptionsMixin,
268268
E extends EmitsOptions = EmitsOptions,
269269
EE extends string = string,
270-
S extends SlotsType = {},
271270
I extends ComponentInjectOptions = {},
272271
II extends string = string,
272+
S extends SlotsType = {},
273273
Props = Prettify<Readonly<{ [key in PropNames]?: any } & EmitsToProps<E>>>
274274
> = ComponentOptionsBase<
275275
Props,
@@ -315,9 +315,9 @@ export type ComponentOptionsWithObjectProps<
315315
Extends extends ComponentOptionsMixin = ComponentOptionsMixin,
316316
E extends EmitsOptions = EmitsOptions,
317317
EE extends string = string,
318-
S extends SlotsType = {},
319318
I extends ComponentInjectOptions = {},
320319
II extends string = string,
320+
S extends SlotsType = {},
321321
Props = Prettify<Readonly<ExtractPropTypes<PropsOptions> & EmitsToProps<E>>>,
322322
Defaults = ExtractDefaultPropTypes<PropsOptions>
323323
> = ComponentOptionsBase<

packages/runtime-core/src/componentPublicInstance.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -164,12 +164,12 @@ export type CreateComponentPublicInstance<
164164
PublicC,
165165
PublicM,
166166
E,
167-
S,
168167
PublicProps,
169168
PublicDefaults,
170169
MakeDefaultsOptional,
171170
ComponentOptionsBase<P, B, D, C, M, Mixin, Extends, E, string, S, Defaults>,
172-
I
171+
I,
172+
S
173173
>
174174

175175
// public properties exposed on the proxy, which is used as the render context
@@ -181,12 +181,12 @@ export type ComponentPublicInstance<
181181
C extends ComputedOptions = {},
182182
M extends MethodOptions = {},
183183
E extends EmitsOptions = {},
184-
S extends SlotsType = {},
185184
PublicProps = P,
186185
Defaults = {},
187186
MakeDefaultsOptional extends boolean = false,
188187
Options = ComponentOptionsBase<any, any, any, any, any, any, any, any, any>,
189-
I extends ComponentInjectOptions = {}
188+
I extends ComponentInjectOptions = {},
189+
S extends SlotsType = {}
190190
> = {
191191
$: ComponentInternalInstance
192192
$data: D

packages/runtime-dom/src/apiCustomElement.ts

+12-12
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ export function defineCustomElement<
5252
Extends extends ComponentOptionsMixin = ComponentOptionsMixin,
5353
E extends EmitsOptions = EmitsOptions,
5454
EE extends string = string,
55-
S extends SlotsType = {},
5655
I extends ComponentInjectOptions = {},
57-
II extends string = string
56+
II extends string = string,
57+
S extends SlotsType = {}
5858
>(
5959
options: ComponentOptionsWithoutProps<
6060
Props,
@@ -66,9 +66,9 @@ export function defineCustomElement<
6666
Extends,
6767
E,
6868
EE,
69-
S,
7069
I,
71-
II
70+
II,
71+
S
7272
> & { styles?: string[] }
7373
): VueElementConstructor<Props>
7474

@@ -83,9 +83,9 @@ export function defineCustomElement<
8383
Extends extends ComponentOptionsMixin = ComponentOptionsMixin,
8484
E extends EmitsOptions = Record<string, any>,
8585
EE extends string = string,
86-
S extends SlotsType = {},
8786
I extends ComponentInjectOptions = {},
88-
II extends string = string
87+
II extends string = string,
88+
S extends SlotsType = {}
8989
>(
9090
options: ComponentOptionsWithArrayProps<
9191
PropNames,
@@ -97,9 +97,9 @@ export function defineCustomElement<
9797
Extends,
9898
E,
9999
EE,
100-
S,
101100
I,
102-
II
101+
II,
102+
S
103103
> & { styles?: string[] }
104104
): VueElementConstructor<{ [K in PropNames]: any }>
105105

@@ -114,9 +114,9 @@ export function defineCustomElement<
114114
Extends extends ComponentOptionsMixin = ComponentOptionsMixin,
115115
E extends EmitsOptions = Record<string, any>,
116116
EE extends string = string,
117-
S extends SlotsType = {},
118117
I extends ComponentInjectOptions = {},
119-
II extends string = string
118+
II extends string = string,
119+
S extends SlotsType = {}
120120
>(
121121
options: ComponentOptionsWithObjectProps<
122122
PropsOptions,
@@ -128,9 +128,9 @@ export function defineCustomElement<
128128
Extends,
129129
E,
130130
EE,
131-
S,
132131
I,
133-
II
132+
II,
133+
S
134134
> & { styles?: string[] }
135135
): VueElementConstructor<ExtractPropTypes<PropsOptions>>
136136

0 commit comments

Comments
 (0)