fix(types): fix defineComponent
inference to Component
(#5949)
This commit is contained in:
parent
3e2850fa6c
commit
7c8f4578e9
@ -111,7 +111,29 @@ export function defineComponent<
|
|||||||
E extends EmitsOptions = EmitsOptions,
|
E extends EmitsOptions = EmitsOptions,
|
||||||
EE extends string = string,
|
EE extends string = string,
|
||||||
Provide extends ComponentProvideOptions = ComponentProvideOptions,
|
Provide extends ComponentProvideOptions = ComponentProvideOptions,
|
||||||
Options extends {} = {}
|
Options extends ComponentOptionsWithoutProps<
|
||||||
|
Props,
|
||||||
|
RawBindings,
|
||||||
|
D,
|
||||||
|
C,
|
||||||
|
M,
|
||||||
|
Mixin,
|
||||||
|
Extends,
|
||||||
|
E,
|
||||||
|
EE,
|
||||||
|
Provide
|
||||||
|
> = ComponentOptionsWithoutProps<
|
||||||
|
Props,
|
||||||
|
RawBindings,
|
||||||
|
D,
|
||||||
|
C,
|
||||||
|
M,
|
||||||
|
Mixin,
|
||||||
|
Extends,
|
||||||
|
E,
|
||||||
|
EE,
|
||||||
|
Provide
|
||||||
|
>
|
||||||
>(
|
>(
|
||||||
options: Options &
|
options: Options &
|
||||||
ComponentOptionsWithoutProps<
|
ComponentOptionsWithoutProps<
|
||||||
@ -154,7 +176,29 @@ export function defineComponent<
|
|||||||
E extends EmitsOptions = Record<string, any>,
|
E extends EmitsOptions = Record<string, any>,
|
||||||
EE extends string = string,
|
EE extends string = string,
|
||||||
Provide extends ComponentProvideOptions = ComponentProvideOptions,
|
Provide extends ComponentProvideOptions = ComponentProvideOptions,
|
||||||
Options extends {} = {}
|
Options extends ComponentOptionsWithArrayProps<
|
||||||
|
PropNames,
|
||||||
|
RawBindings,
|
||||||
|
D,
|
||||||
|
C,
|
||||||
|
M,
|
||||||
|
Mixin,
|
||||||
|
Extends,
|
||||||
|
E,
|
||||||
|
EE,
|
||||||
|
Provide
|
||||||
|
> = ComponentOptionsWithArrayProps<
|
||||||
|
PropNames,
|
||||||
|
RawBindings,
|
||||||
|
D,
|
||||||
|
C,
|
||||||
|
M,
|
||||||
|
Mixin,
|
||||||
|
Extends,
|
||||||
|
E,
|
||||||
|
EE,
|
||||||
|
Provide
|
||||||
|
>
|
||||||
>(
|
>(
|
||||||
options: Options &
|
options: Options &
|
||||||
ComponentOptionsWithArrayProps<
|
ComponentOptionsWithArrayProps<
|
||||||
@ -198,7 +242,29 @@ export function defineComponent<
|
|||||||
E extends EmitsOptions = Record<string, any>,
|
E extends EmitsOptions = Record<string, any>,
|
||||||
EE extends string = string,
|
EE extends string = string,
|
||||||
Provide extends ComponentProvideOptions = ComponentProvideOptions,
|
Provide extends ComponentProvideOptions = ComponentProvideOptions,
|
||||||
Options extends {} = {}
|
Options extends ComponentOptionsWithObjectProps<
|
||||||
|
PropsOptions,
|
||||||
|
RawBindings,
|
||||||
|
D,
|
||||||
|
C,
|
||||||
|
M,
|
||||||
|
Mixin,
|
||||||
|
Extends,
|
||||||
|
E,
|
||||||
|
EE,
|
||||||
|
Provide
|
||||||
|
> = ComponentOptionsWithObjectProps<
|
||||||
|
PropsOptions,
|
||||||
|
RawBindings,
|
||||||
|
D,
|
||||||
|
C,
|
||||||
|
M,
|
||||||
|
Mixin,
|
||||||
|
Extends,
|
||||||
|
E,
|
||||||
|
EE,
|
||||||
|
Provide
|
||||||
|
>
|
||||||
>(
|
>(
|
||||||
options: Options &
|
options: Options &
|
||||||
ComponentOptionsWithObjectProps<
|
ComponentOptionsWithObjectProps<
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import {
|
import {
|
||||||
describe,
|
describe,
|
||||||
|
test,
|
||||||
Component,
|
Component,
|
||||||
defineComponent,
|
defineComponent,
|
||||||
PropType,
|
PropType,
|
||||||
@ -1045,7 +1046,7 @@ describe('emits', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
describe('componentOptions setup should be `SetupContext`', () => {
|
describe('componentOptions setup should be `SetupContext`', () => {
|
||||||
expect<ComponentOptions['setup']>(
|
expectType<ComponentOptions['setup']>(
|
||||||
{} as (props: Record<string, any>, ctx: SetupContext) => any
|
{} as (props: Record<string, any>, ctx: SetupContext) => any
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
@ -1141,6 +1142,20 @@ describe('async setup', () => {
|
|||||||
vm.a = 2
|
vm.a = 2
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// #5948
|
||||||
|
describe('DefineComponent should infer correct types when assigning to Component', () => {
|
||||||
|
let component: Component
|
||||||
|
component = defineComponent({
|
||||||
|
setup(_, { attrs, slots }) {
|
||||||
|
// @ts-expect-error should not be any
|
||||||
|
expectType<[]>(attrs)
|
||||||
|
// @ts-expect-error should not be any
|
||||||
|
expectType<[]>(slots)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
expectType<Component>(component)
|
||||||
|
})
|
||||||
|
|
||||||
// check if defineComponent can be exported
|
// check if defineComponent can be exported
|
||||||
export default {
|
export default {
|
||||||
// function components
|
// function components
|
||||||
|
3
test-dts/index.d.ts
vendored
3
test-dts/index.d.ts
vendored
@ -4,6 +4,7 @@
|
|||||||
export * from '@vue/runtime-dom'
|
export * from '@vue/runtime-dom'
|
||||||
|
|
||||||
export function describe(_name: string, _fn: () => void): void
|
export function describe(_name: string, _fn: () => void): void
|
||||||
|
export function test(_name: string, _fn: () => any): void
|
||||||
|
|
||||||
export function expectType<T>(value: T): void
|
export function expectType<T>(value: T): void
|
||||||
export function expectError<T>(value: T): void
|
export function expectError<T>(value: T): void
|
||||||
@ -15,4 +16,4 @@ export type IsUnion<T, U extends T = T> = (
|
|||||||
? false
|
? false
|
||||||
: true
|
: true
|
||||||
|
|
||||||
export type IsAny<T> = 0 extends (1 & T) ? true : false
|
export type IsAny<T> = 0 extends 1 & T ? true : false
|
||||||
|
Loading…
Reference in New Issue
Block a user