fix(types): component instance inference without props (#2145)

This commit is contained in:
Anthony Fu 2020-09-18 12:13:47 +08:00 committed by GitHub
parent 1c9a0b3e19
commit 57bdaa2220
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 18 deletions

View File

@ -94,8 +94,8 @@ export function defineComponent<
Props = {},
RawBindings = {},
D = {},
C extends ComputedOptions = ComputedOptions,
M extends MethodOptions = MethodOptions,
C extends ComputedOptions = {},
M extends MethodOptions = {},
Mixin extends ComponentOptionsMixin = ComponentOptionsMixin,
Extends extends ComponentOptionsMixin = ComponentOptionsMixin,
E extends EmitsOptions = EmitsOptions,

View File

@ -166,8 +166,7 @@ export type ComponentOptionsWithoutProps<
Mixin extends ComponentOptionsMixin = ComponentOptionsMixin,
Extends extends ComponentOptionsMixin = ComponentOptionsMixin,
E extends EmitsOptions = EmitsOptions,
EE extends string = string,
Defaults = {}
EE extends string = string
> = ComponentOptionsBase<
Props,
RawBindings,
@ -178,23 +177,11 @@ export type ComponentOptionsWithoutProps<
Extends,
E,
EE,
Defaults
{}
> & {
props?: undefined
} & ThisType<
CreateComponentPublicInstance<
{},
RawBindings,
D,
C,
M,
Mixin,
Extends,
E,
Readonly<Props>,
Defaults,
false
>
CreateComponentPublicInstance<{}, RawBindings, D, C, M, Mixin, Extends, E>
>
export type ComponentOptionsWithArrayProps<

View File

@ -190,6 +190,12 @@ describe('object props', () => {
expectType<ExpectedProps['ggg']>(setup.setupProps.ggg)
expectType<ExpectedProps['ffff']>(setup.setupProps.ffff)
expectType<ExpectedProps['validated']>(setup.setupProps.validated)
// instance
const instance = new MyComponent()
expectType<number>(instance.setupA)
// @ts-expect-error
instance.notExist
})
describe('options', () => {
@ -356,6 +362,12 @@ describe('no props', () => {
expectType<number>(rawBindings.setupA)
expectType<number>(setup.setupA)
// instance
const instance = new MyComponent()
expectType<number>(instance.setupA)
// @ts-expect-error
instance.notExist
})
describe('options', () => {