fix(types): component instance inference without props (#2145)
This commit is contained in:
parent
1c9a0b3e19
commit
57bdaa2220
@ -94,8 +94,8 @@ export function defineComponent<
|
|||||||
Props = {},
|
Props = {},
|
||||||
RawBindings = {},
|
RawBindings = {},
|
||||||
D = {},
|
D = {},
|
||||||
C extends ComputedOptions = ComputedOptions,
|
C extends ComputedOptions = {},
|
||||||
M extends MethodOptions = MethodOptions,
|
M extends MethodOptions = {},
|
||||||
Mixin extends ComponentOptionsMixin = ComponentOptionsMixin,
|
Mixin extends ComponentOptionsMixin = ComponentOptionsMixin,
|
||||||
Extends extends ComponentOptionsMixin = ComponentOptionsMixin,
|
Extends extends ComponentOptionsMixin = ComponentOptionsMixin,
|
||||||
E extends EmitsOptions = EmitsOptions,
|
E extends EmitsOptions = EmitsOptions,
|
||||||
|
@ -166,8 +166,7 @@ export type ComponentOptionsWithoutProps<
|
|||||||
Mixin extends ComponentOptionsMixin = ComponentOptionsMixin,
|
Mixin extends ComponentOptionsMixin = ComponentOptionsMixin,
|
||||||
Extends extends ComponentOptionsMixin = ComponentOptionsMixin,
|
Extends extends ComponentOptionsMixin = ComponentOptionsMixin,
|
||||||
E extends EmitsOptions = EmitsOptions,
|
E extends EmitsOptions = EmitsOptions,
|
||||||
EE extends string = string,
|
EE extends string = string
|
||||||
Defaults = {}
|
|
||||||
> = ComponentOptionsBase<
|
> = ComponentOptionsBase<
|
||||||
Props,
|
Props,
|
||||||
RawBindings,
|
RawBindings,
|
||||||
@ -178,23 +177,11 @@ export type ComponentOptionsWithoutProps<
|
|||||||
Extends,
|
Extends,
|
||||||
E,
|
E,
|
||||||
EE,
|
EE,
|
||||||
Defaults
|
{}
|
||||||
> & {
|
> & {
|
||||||
props?: undefined
|
props?: undefined
|
||||||
} & ThisType<
|
} & ThisType<
|
||||||
CreateComponentPublicInstance<
|
CreateComponentPublicInstance<{}, RawBindings, D, C, M, Mixin, Extends, E>
|
||||||
{},
|
|
||||||
RawBindings,
|
|
||||||
D,
|
|
||||||
C,
|
|
||||||
M,
|
|
||||||
Mixin,
|
|
||||||
Extends,
|
|
||||||
E,
|
|
||||||
Readonly<Props>,
|
|
||||||
Defaults,
|
|
||||||
false
|
|
||||||
>
|
|
||||||
>
|
>
|
||||||
|
|
||||||
export type ComponentOptionsWithArrayProps<
|
export type ComponentOptionsWithArrayProps<
|
||||||
|
@ -190,6 +190,12 @@ describe('object props', () => {
|
|||||||
expectType<ExpectedProps['ggg']>(setup.setupProps.ggg)
|
expectType<ExpectedProps['ggg']>(setup.setupProps.ggg)
|
||||||
expectType<ExpectedProps['ffff']>(setup.setupProps.ffff)
|
expectType<ExpectedProps['ffff']>(setup.setupProps.ffff)
|
||||||
expectType<ExpectedProps['validated']>(setup.setupProps.validated)
|
expectType<ExpectedProps['validated']>(setup.setupProps.validated)
|
||||||
|
|
||||||
|
// instance
|
||||||
|
const instance = new MyComponent()
|
||||||
|
expectType<number>(instance.setupA)
|
||||||
|
// @ts-expect-error
|
||||||
|
instance.notExist
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('options', () => {
|
describe('options', () => {
|
||||||
@ -356,6 +362,12 @@ describe('no props', () => {
|
|||||||
|
|
||||||
expectType<number>(rawBindings.setupA)
|
expectType<number>(rawBindings.setupA)
|
||||||
expectType<number>(setup.setupA)
|
expectType<number>(setup.setupA)
|
||||||
|
|
||||||
|
// instance
|
||||||
|
const instance = new MyComponent()
|
||||||
|
expectType<number>(instance.setupA)
|
||||||
|
// @ts-expect-error
|
||||||
|
instance.notExist
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('options', () => {
|
describe('options', () => {
|
||||||
|
Loading…
Reference in New Issue
Block a user