fix(types): restore DefineComponent argument order
This is necessary for compatibility w/ tsc-generated component types using DefineComponent. revert #5416 reopen #3796 fix #5967
This commit is contained in:
parent
583b625987
commit
8071ef47b5
@ -111,7 +111,7 @@ export function defineAsyncComponent<
|
||||
)
|
||||
}
|
||||
|
||||
return defineComponent<{}>({
|
||||
return defineComponent({
|
||||
name: 'AsyncComponentWrapper',
|
||||
|
||||
__asyncLoader: load,
|
||||
|
@ -6,8 +6,7 @@ import {
|
||||
ComponentOptionsWithObjectProps,
|
||||
ComponentOptionsMixin,
|
||||
RenderFunction,
|
||||
ComponentOptionsBase,
|
||||
ComponentProvideOptions
|
||||
ComponentOptionsBase
|
||||
} from './componentOptions'
|
||||
import {
|
||||
SetupContext,
|
||||
@ -41,8 +40,6 @@ export type DefineComponent<
|
||||
Extends extends ComponentOptionsMixin = ComponentOptionsMixin,
|
||||
E extends EmitsOptions = {},
|
||||
EE extends string = string,
|
||||
Provide extends ComponentProvideOptions = ComponentProvideOptions,
|
||||
RawOptions extends {} = {},
|
||||
PP = PublicProps,
|
||||
Props = Readonly<
|
||||
PropsOrPropOptions extends ComponentPropsOptions
|
||||
@ -51,8 +48,7 @@ export type DefineComponent<
|
||||
> &
|
||||
({} extends E ? {} : EmitsToProps<E>),
|
||||
Defaults = ExtractDefaultPropTypes<PropsOrPropOptions>
|
||||
> = RawOptions &
|
||||
ComponentPublicInstanceConstructor<
|
||||
> = ComponentPublicInstanceConstructor<
|
||||
CreateComponentPublicInstance<
|
||||
Props,
|
||||
RawBindings,
|
||||
@ -67,7 +63,7 @@ export type DefineComponent<
|
||||
true
|
||||
> &
|
||||
Props
|
||||
> &
|
||||
> &
|
||||
ComponentOptionsBase<
|
||||
Props,
|
||||
RawBindings,
|
||||
@ -78,8 +74,7 @@ export type DefineComponent<
|
||||
Extends,
|
||||
E,
|
||||
EE,
|
||||
Defaults,
|
||||
Provide
|
||||
Defaults
|
||||
> &
|
||||
PP
|
||||
|
||||
@ -109,34 +104,9 @@ export function defineComponent<
|
||||
Mixin extends ComponentOptionsMixin = ComponentOptionsMixin,
|
||||
Extends extends ComponentOptionsMixin = ComponentOptionsMixin,
|
||||
E extends EmitsOptions = EmitsOptions,
|
||||
EE extends string = string,
|
||||
Provide extends ComponentProvideOptions = ComponentProvideOptions,
|
||||
Options extends ComponentOptionsWithoutProps<
|
||||
Props,
|
||||
RawBindings,
|
||||
D,
|
||||
C,
|
||||
M,
|
||||
Mixin,
|
||||
Extends,
|
||||
E,
|
||||
EE,
|
||||
Provide
|
||||
> = ComponentOptionsWithoutProps<
|
||||
Props,
|
||||
RawBindings,
|
||||
D,
|
||||
C,
|
||||
M,
|
||||
Mixin,
|
||||
Extends,
|
||||
E,
|
||||
EE,
|
||||
Provide
|
||||
>
|
||||
EE extends string = string
|
||||
>(
|
||||
options: Options &
|
||||
ComponentOptionsWithoutProps<
|
||||
options: ComponentOptionsWithoutProps<
|
||||
Props,
|
||||
RawBindings,
|
||||
D,
|
||||
@ -145,22 +115,9 @@ export function defineComponent<
|
||||
Mixin,
|
||||
Extends,
|
||||
E,
|
||||
EE,
|
||||
Provide
|
||||
EE
|
||||
>
|
||||
): DefineComponent<
|
||||
Props,
|
||||
RawBindings,
|
||||
D,
|
||||
C,
|
||||
M,
|
||||
Mixin,
|
||||
Extends,
|
||||
E,
|
||||
EE,
|
||||
Provide,
|
||||
Options
|
||||
>
|
||||
): DefineComponent<Props, RawBindings, D, C, M, Mixin, Extends, E, EE>
|
||||
|
||||
// overload 3: object format with array props declaration
|
||||
// props inferred as { [key in PropNames]?: any }
|
||||
@ -174,34 +131,9 @@ export function defineComponent<
|
||||
Mixin extends ComponentOptionsMixin = ComponentOptionsMixin,
|
||||
Extends extends ComponentOptionsMixin = ComponentOptionsMixin,
|
||||
E extends EmitsOptions = Record<string, any>,
|
||||
EE extends string = string,
|
||||
Provide extends ComponentProvideOptions = ComponentProvideOptions,
|
||||
Options extends ComponentOptionsWithArrayProps<
|
||||
PropNames,
|
||||
RawBindings,
|
||||
D,
|
||||
C,
|
||||
M,
|
||||
Mixin,
|
||||
Extends,
|
||||
E,
|
||||
EE,
|
||||
Provide
|
||||
> = ComponentOptionsWithArrayProps<
|
||||
PropNames,
|
||||
RawBindings,
|
||||
D,
|
||||
C,
|
||||
M,
|
||||
Mixin,
|
||||
Extends,
|
||||
E,
|
||||
EE,
|
||||
Provide
|
||||
>
|
||||
EE extends string = string
|
||||
>(
|
||||
options: Options &
|
||||
ComponentOptionsWithArrayProps<
|
||||
options: ComponentOptionsWithArrayProps<
|
||||
PropNames,
|
||||
RawBindings,
|
||||
D,
|
||||
@ -210,8 +142,7 @@ export function defineComponent<
|
||||
Mixin,
|
||||
Extends,
|
||||
E,
|
||||
EE,
|
||||
Provide
|
||||
EE
|
||||
>
|
||||
): DefineComponent<
|
||||
Readonly<{ [key in PropNames]?: any }>,
|
||||
@ -222,9 +153,7 @@ export function defineComponent<
|
||||
Mixin,
|
||||
Extends,
|
||||
E,
|
||||
EE,
|
||||
Provide,
|
||||
Options
|
||||
EE
|
||||
>
|
||||
|
||||
// overload 4: object format with object props declaration
|
||||
@ -240,34 +169,9 @@ export function defineComponent<
|
||||
Mixin extends ComponentOptionsMixin = ComponentOptionsMixin,
|
||||
Extends extends ComponentOptionsMixin = ComponentOptionsMixin,
|
||||
E extends EmitsOptions = Record<string, any>,
|
||||
EE extends string = string,
|
||||
Provide extends ComponentProvideOptions = ComponentProvideOptions,
|
||||
Options extends ComponentOptionsWithObjectProps<
|
||||
PropsOptions,
|
||||
RawBindings,
|
||||
D,
|
||||
C,
|
||||
M,
|
||||
Mixin,
|
||||
Extends,
|
||||
E,
|
||||
EE,
|
||||
Provide
|
||||
> = ComponentOptionsWithObjectProps<
|
||||
PropsOptions,
|
||||
RawBindings,
|
||||
D,
|
||||
C,
|
||||
M,
|
||||
Mixin,
|
||||
Extends,
|
||||
E,
|
||||
EE,
|
||||
Provide
|
||||
>
|
||||
EE extends string = string
|
||||
>(
|
||||
options: Options &
|
||||
ComponentOptionsWithObjectProps<
|
||||
options: ComponentOptionsWithObjectProps<
|
||||
PropsOptions,
|
||||
RawBindings,
|
||||
D,
|
||||
@ -276,22 +180,9 @@ export function defineComponent<
|
||||
Mixin,
|
||||
Extends,
|
||||
E,
|
||||
EE,
|
||||
Provide
|
||||
EE
|
||||
>
|
||||
): DefineComponent<
|
||||
PropsOptions,
|
||||
RawBindings,
|
||||
D,
|
||||
C,
|
||||
M,
|
||||
Mixin,
|
||||
Extends,
|
||||
E,
|
||||
EE,
|
||||
Provide,
|
||||
Options
|
||||
>
|
||||
): DefineComponent<PropsOptions, RawBindings, D, C, M, Mixin, Extends, E, EE>
|
||||
|
||||
// implementation, close to no-op
|
||||
export function defineComponent(options: unknown) {
|
||||
|
@ -118,9 +118,8 @@ export interface ComponentOptionsBase<
|
||||
Extends extends ComponentOptionsMixin,
|
||||
E extends EmitsOptions,
|
||||
EE extends string = string,
|
||||
Defaults = {},
|
||||
Provide extends ComponentProvideOptions = ComponentProvideOptions
|
||||
> extends LegacyOptions<Props, D, C, M, Mixin, Extends, Provide>,
|
||||
Defaults = {}
|
||||
> extends LegacyOptions<Props, D, C, M, Mixin, Extends>,
|
||||
ComponentInternalOptions,
|
||||
ComponentCustomOptions {
|
||||
setup?: (
|
||||
@ -226,7 +225,6 @@ export type ComponentOptionsWithoutProps<
|
||||
Extends extends ComponentOptionsMixin = ComponentOptionsMixin,
|
||||
E extends EmitsOptions = EmitsOptions,
|
||||
EE extends string = string,
|
||||
Provide extends ComponentProvideOptions = ComponentProvideOptions,
|
||||
PE = Props & EmitsToProps<E>
|
||||
> = ComponentOptionsBase<
|
||||
PE,
|
||||
@ -238,8 +236,7 @@ export type ComponentOptionsWithoutProps<
|
||||
Extends,
|
||||
E,
|
||||
EE,
|
||||
{},
|
||||
Provide
|
||||
{}
|
||||
> & {
|
||||
props?: undefined
|
||||
} & ThisType<
|
||||
@ -256,7 +253,6 @@ export type ComponentOptionsWithArrayProps<
|
||||
Extends extends ComponentOptionsMixin = ComponentOptionsMixin,
|
||||
E extends EmitsOptions = EmitsOptions,
|
||||
EE extends string = string,
|
||||
Provide extends ComponentProvideOptions = ComponentProvideOptions,
|
||||
Props = Readonly<{ [key in PropNames]?: any }> & EmitsToProps<E>
|
||||
> = ComponentOptionsBase<
|
||||
Props,
|
||||
@ -268,8 +264,7 @@ export type ComponentOptionsWithArrayProps<
|
||||
Extends,
|
||||
E,
|
||||
EE,
|
||||
{},
|
||||
Provide
|
||||
{}
|
||||
> & {
|
||||
props: PropNames[]
|
||||
} & ThisType<
|
||||
@ -295,7 +290,6 @@ export type ComponentOptionsWithObjectProps<
|
||||
Extends extends ComponentOptionsMixin = ComponentOptionsMixin,
|
||||
E extends EmitsOptions = EmitsOptions,
|
||||
EE extends string = string,
|
||||
Provide extends ComponentProvideOptions = ComponentProvideOptions,
|
||||
Props = Readonly<ExtractPropTypes<PropsOptions>> & EmitsToProps<E>,
|
||||
Defaults = ExtractDefaultPropTypes<PropsOptions>
|
||||
> = ComponentOptionsBase<
|
||||
@ -308,8 +302,7 @@ export type ComponentOptionsWithObjectProps<
|
||||
Extends,
|
||||
E,
|
||||
EE,
|
||||
Defaults,
|
||||
Provide
|
||||
Defaults
|
||||
> & {
|
||||
props: PropsOptions & ThisType<void>
|
||||
} & ThisType<
|
||||
@ -409,8 +402,7 @@ interface LegacyOptions<
|
||||
C extends ComputedOptions,
|
||||
M extends MethodOptions,
|
||||
Mixin extends ComponentOptionsMixin,
|
||||
Extends extends ComponentOptionsMixin,
|
||||
Provide extends ComponentProvideOptions = ComponentProvideOptions
|
||||
Extends extends ComponentOptionsMixin
|
||||
> {
|
||||
compatConfig?: CompatConfig
|
||||
|
||||
@ -444,7 +436,7 @@ interface LegacyOptions<
|
||||
computed?: C
|
||||
methods?: M
|
||||
watch?: ComponentWatchOptions
|
||||
provide?: Provide
|
||||
provide?: ComponentProvideOptions
|
||||
inject?: ComponentInjectOptions
|
||||
|
||||
// assets
|
||||
|
@ -34,8 +34,7 @@ import {
|
||||
OptionTypesKeys,
|
||||
resolveMergedOptions,
|
||||
shouldCacheAccess,
|
||||
MergedComponentOptionsOverride,
|
||||
ComponentProvideOptions
|
||||
MergedComponentOptionsOverride
|
||||
} from './componentOptions'
|
||||
import { EmitsOptions, EmitFn } from './componentEmits'
|
||||
import { Slots } from './componentSlots'
|
||||
@ -151,8 +150,7 @@ export type CreateComponentPublicInstance<
|
||||
PublicM extends MethodOptions = UnwrapMixinsType<PublicMixin, 'M'> &
|
||||
EnsureNonVoid<M>,
|
||||
PublicDefaults = UnwrapMixinsType<PublicMixin, 'Defaults'> &
|
||||
EnsureNonVoid<Defaults>,
|
||||
Provide extends ComponentProvideOptions = ComponentProvideOptions
|
||||
EnsureNonVoid<Defaults>
|
||||
> = ComponentPublicInstance<
|
||||
PublicP,
|
||||
PublicB,
|
||||
@ -163,19 +161,7 @@ export type CreateComponentPublicInstance<
|
||||
PublicProps,
|
||||
PublicDefaults,
|
||||
MakeDefaultsOptional,
|
||||
ComponentOptionsBase<
|
||||
P,
|
||||
B,
|
||||
D,
|
||||
C,
|
||||
M,
|
||||
Mixin,
|
||||
Extends,
|
||||
E,
|
||||
string,
|
||||
Defaults,
|
||||
Provide
|
||||
>
|
||||
ComponentOptionsBase<P, B, D, C, M, Mixin, Extends, E, string, Defaults>
|
||||
>
|
||||
|
||||
// public properties exposed on the proxy, which is used as the render context
|
||||
|
@ -264,18 +264,6 @@ describe('with object props', () => {
|
||||
|
||||
expectType<Component>(MyComponent)
|
||||
|
||||
expectType<typeof props>(MyComponent.props)
|
||||
// @ts-expect-error it should be an object and not any
|
||||
expectError<[]>(MyComponent.props)
|
||||
|
||||
expectType<() => {}>(MyComponent.provide)
|
||||
// @ts-expect-error
|
||||
expectError<[]>(MyComponent.provide)
|
||||
|
||||
expectType<() => null>(MyComponent.render)
|
||||
|
||||
expectType<Function | undefined>(defineComponent({}).render)
|
||||
|
||||
// Test TSX
|
||||
expectType<JSX.Element>(
|
||||
<MyComponent
|
||||
@ -1175,3 +1163,24 @@ export default {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// code generated by tsc / vue-tsc, make sure this continues to work
|
||||
// so we don't accidentally change the args order of DefineComponent
|
||||
declare const MyButton: import('vue').DefineComponent<
|
||||
{},
|
||||
() => JSX.Element,
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
import('vue').ComponentOptionsMixin,
|
||||
import('vue').ComponentOptionsMixin,
|
||||
import('vue').EmitsOptions,
|
||||
string,
|
||||
import('vue').VNodeProps &
|
||||
import('vue').AllowedComponentProps &
|
||||
import('vue').ComponentCustomProps,
|
||||
Readonly<import('vue').ExtractPropTypes<{}>>,
|
||||
{}
|
||||
>
|
||||
|
||||
;<MyButton class="x" />
|
||||
|
Loading…
x
Reference in New Issue
Block a user