fix(types): fix defineComponent inference to Component (#5949)

This commit is contained in:
Carlos Rodrigues
2022-05-19 00:34:35 +01:00
committed by GitHub
parent 3e2850fa6c
commit 7c8f4578e9
3 changed files with 87 additions and 5 deletions

View File

@@ -1,5 +1,6 @@
import {
describe,
test,
Component,
defineComponent,
PropType,
@@ -1045,7 +1046,7 @@ describe('emits', () => {
})
describe('componentOptions setup should be `SetupContext`', () => {
expect<ComponentOptions['setup']>(
expectType<ComponentOptions['setup']>(
{} as (props: Record<string, any>, ctx: SetupContext) => any
)
})
@@ -1141,6 +1142,20 @@ describe('async setup', () => {
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
export default {
// function components

3
test-dts/index.d.ts vendored
View File

@@ -4,6 +4,7 @@
export * from '@vue/runtime-dom'
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 expectError<T>(value: T): void
@@ -15,4 +16,4 @@ export type IsUnion<T, U extends T = T> = (
? false
: true
export type IsAny<T> = 0 extends (1 & T) ? true : false
export type IsAny<T> = 0 extends 1 & T ? true : false