Skip to content

Commit

Permalink
fix(types): retain type parameters order for public types
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Apr 5, 2023
1 parent b117b88 commit bdf557f
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 38 deletions.
2 changes: 1 addition & 1 deletion packages/dts-test/defineComponent.test-d.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1494,9 +1494,9 @@ declare const MyButton: DefineComponent<
ComponentOptionsMixin,
EmitsOptions,
string,
{},
VNodeProps & AllowedComponentProps & ComponentCustomProps,
Readonly<ExtractPropTypes<{}>>,
{},
{}
>
;<MyButton class="x" />
70 changes: 52 additions & 18 deletions packages/runtime-core/src/apiDefineComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ export type PublicProps = VNodeProps &
AllowedComponentProps &
ComponentCustomProps

type ResolveProps<PropsOrPropOptions, E extends EmitsOptions> = Readonly<
PropsOrPropOptions extends ComponentPropsOptions
? ExtractPropTypes<PropsOrPropOptions>
: PropsOrPropOptions
> &
({} extends E ? {} : EmitsToProps<E>)

export type DefineComponent<
PropsOrPropOptions = {},
RawBindings = {},
Expand All @@ -44,15 +51,10 @@ export type DefineComponent<
Extends extends ComponentOptionsMixin = ComponentOptionsMixin,
E extends EmitsOptions = {},
EE extends string = string,
S extends SlotsType = {},
PP = PublicProps,
Props = Readonly<
PropsOrPropOptions extends ComponentPropsOptions
? ExtractPropTypes<PropsOrPropOptions>
: PropsOrPropOptions
> &
({} extends E ? {} : EmitsToProps<E>),
Defaults = ExtractDefaultPropTypes<PropsOrPropOptions>
Props = ResolveProps<PropsOrPropOptions, E>,
Defaults = ExtractDefaultPropTypes<PropsOrPropOptions>,
S extends SlotsType = {}
> = ComponentPublicInstanceConstructor<
CreateComponentPublicInstance<
Props,
Expand Down Expand Up @@ -152,11 +154,25 @@ export function defineComponent<
Extends,
E,
EE,
S,
I,
II
II,
S
>
): DefineComponent<Props, RawBindings, D, C, M, Mixin, Extends, E, EE, S>
): DefineComponent<
Props,
RawBindings,
D,
C,
M,
Mixin,
Extends,
E,
EE,
PublicProps,
ResolveProps<Props, E>,
ExtractDefaultPropTypes<Props>,
S
>

// overload 3: object format with array props declaration
// props inferred as { [key in PropNames]?: any }
Expand All @@ -173,7 +189,8 @@ export function defineComponent<
EE extends string = string,
S extends SlotsType = {},
I extends ComponentInjectOptions = {},
II extends string = string
II extends string = string,
Props = Readonly<{ [key in PropNames]?: any }>
>(
options: ComponentOptionsWithArrayProps<
PropNames,
Expand All @@ -185,12 +202,12 @@ export function defineComponent<
Extends,
E,
EE,
S,
I,
II
II,
S
>
): DefineComponent<
Readonly<{ [key in PropNames]?: any }>,
Props,
RawBindings,
D,
C,
Expand All @@ -199,6 +216,9 @@ export function defineComponent<
Extends,
E,
EE,
PublicProps,
ResolveProps<Props, E>,
ExtractDefaultPropTypes<Props>,
S
>

Expand Down Expand Up @@ -230,11 +250,25 @@ export function defineComponent<
Extends,
E,
EE,
S,
I,
II
II,
S
>
): DefineComponent<PropsOptions, RawBindings, D, C, M, Mixin, Extends, E, EE, S>
): DefineComponent<
PropsOptions,
RawBindings,
D,
C,
M,
Mixin,
Extends,
E,
EE,
PublicProps,
ResolveProps<PropsOptions, E>,
ExtractDefaultPropTypes<PropsOptions>,
S
>

// implementation, close to no-op
export function defineComponent(
Expand Down
6 changes: 3 additions & 3 deletions packages/runtime-core/src/componentOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,9 @@ export type ComponentOptionsWithoutProps<
Extends extends ComponentOptionsMixin = ComponentOptionsMixin,
E extends EmitsOptions = EmitsOptions,
EE extends string = string,
S extends SlotsType = {},
I extends ComponentInjectOptions = {},
II extends string = string,
S extends SlotsType = {},
PE = Props & EmitsToProps<E>
> = ComponentOptionsBase<
PE,
Expand Down Expand Up @@ -267,9 +267,9 @@ export type ComponentOptionsWithArrayProps<
Extends extends ComponentOptionsMixin = ComponentOptionsMixin,
E extends EmitsOptions = EmitsOptions,
EE extends string = string,
S extends SlotsType = {},
I extends ComponentInjectOptions = {},
II extends string = string,
S extends SlotsType = {},
Props = Prettify<Readonly<{ [key in PropNames]?: any } & EmitsToProps<E>>>
> = ComponentOptionsBase<
Props,
Expand Down Expand Up @@ -315,9 +315,9 @@ export type ComponentOptionsWithObjectProps<
Extends extends ComponentOptionsMixin = ComponentOptionsMixin,
E extends EmitsOptions = EmitsOptions,
EE extends string = string,
S extends SlotsType = {},
I extends ComponentInjectOptions = {},
II extends string = string,
S extends SlotsType = {},
Props = Prettify<Readonly<ExtractPropTypes<PropsOptions> & EmitsToProps<E>>>,
Defaults = ExtractDefaultPropTypes<PropsOptions>
> = ComponentOptionsBase<
Expand Down
8 changes: 4 additions & 4 deletions packages/runtime-core/src/componentPublicInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,12 @@ export type CreateComponentPublicInstance<
PublicC,
PublicM,
E,
S,
PublicProps,
PublicDefaults,
MakeDefaultsOptional,
ComponentOptionsBase<P, B, D, C, M, Mixin, Extends, E, string, S, Defaults>,
I
I,
S
>

// public properties exposed on the proxy, which is used as the render context
Expand All @@ -181,12 +181,12 @@ export type ComponentPublicInstance<
C extends ComputedOptions = {},
M extends MethodOptions = {},
E extends EmitsOptions = {},
S extends SlotsType = {},
PublicProps = P,
Defaults = {},
MakeDefaultsOptional extends boolean = false,
Options = ComponentOptionsBase<any, any, any, any, any, any, any, any, any>,
I extends ComponentInjectOptions = {}
I extends ComponentInjectOptions = {},
S extends SlotsType = {}
> = {
$: ComponentInternalInstance
$data: D
Expand Down
24 changes: 12 additions & 12 deletions packages/runtime-dom/src/apiCustomElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ export function defineCustomElement<
Extends extends ComponentOptionsMixin = ComponentOptionsMixin,
E extends EmitsOptions = EmitsOptions,
EE extends string = string,
S extends SlotsType = {},
I extends ComponentInjectOptions = {},
II extends string = string
II extends string = string,
S extends SlotsType = {}
>(
options: ComponentOptionsWithoutProps<
Props,
Expand All @@ -66,9 +66,9 @@ export function defineCustomElement<
Extends,
E,
EE,
S,
I,
II
II,
S
> & { styles?: string[] }
): VueElementConstructor<Props>

Expand All @@ -83,9 +83,9 @@ export function defineCustomElement<
Extends extends ComponentOptionsMixin = ComponentOptionsMixin,
E extends EmitsOptions = Record<string, any>,
EE extends string = string,
S extends SlotsType = {},
I extends ComponentInjectOptions = {},
II extends string = string
II extends string = string,
S extends SlotsType = {}
>(
options: ComponentOptionsWithArrayProps<
PropNames,
Expand All @@ -97,9 +97,9 @@ export function defineCustomElement<
Extends,
E,
EE,
S,
I,
II
II,
S
> & { styles?: string[] }
): VueElementConstructor<{ [K in PropNames]: any }>

Expand All @@ -114,9 +114,9 @@ export function defineCustomElement<
Extends extends ComponentOptionsMixin = ComponentOptionsMixin,
E extends EmitsOptions = Record<string, any>,
EE extends string = string,
S extends SlotsType = {},
I extends ComponentInjectOptions = {},
II extends string = string
II extends string = string,
S extends SlotsType = {}
>(
options: ComponentOptionsWithObjectProps<
PropsOptions,
Expand All @@ -128,9 +128,9 @@ export function defineCustomElement<
Extends,
E,
EE,
S,
I,
II
II,
S
> & { styles?: string[] }
): VueElementConstructor<ExtractPropTypes<PropsOptions>>

Expand Down

0 comments on commit bdf557f

Please sign in to comment.