Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/runtime-core/src/apiDefineComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
19 changes: 3 additions & 16 deletions packages/runtime-core/src/componentOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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<
Expand Down
12 changes: 12 additions & 0 deletions test-dts/component.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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', () => {
Expand Down