mirror of https://github.com/vuejs/core.git
fix(types): fix instance type when props type is incompatible with setup returned type (#7338)
close #5885
This commit is contained in:
parent
657476dcdb
commit
0e1e8f919e
|
@ -1472,6 +1472,31 @@ describe('slots', () => {
|
||||||
expectType<Slots | undefined>(new comp2().$slots)
|
expectType<Slots | undefined>(new comp2().$slots)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// #5885
|
||||||
|
describe('should work when props type is incompatible with setup returned type ', () => {
|
||||||
|
type SizeType = 'small' | 'big'
|
||||||
|
const Comp = defineComponent({
|
||||||
|
props: {
|
||||||
|
size: {
|
||||||
|
type: String as PropType<SizeType>,
|
||||||
|
required: true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
setup(props) {
|
||||||
|
expectType<SizeType>(props.size)
|
||||||
|
return {
|
||||||
|
size: 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
type CompInstance = InstanceType<typeof Comp>
|
||||||
|
|
||||||
|
const CompA = {} as CompInstance
|
||||||
|
expectType<ComponentPublicInstance>(CompA)
|
||||||
|
expectType<number>(CompA.size)
|
||||||
|
expectType<SizeType>(CompA.$props.size)
|
||||||
|
})
|
||||||
|
|
||||||
import {
|
import {
|
||||||
DefineComponent,
|
DefineComponent,
|
||||||
ComponentOptionsMixin,
|
ComponentOptionsMixin,
|
||||||
|
|
|
@ -70,8 +70,7 @@ export type DefineComponent<
|
||||||
true,
|
true,
|
||||||
{},
|
{},
|
||||||
S
|
S
|
||||||
> &
|
>
|
||||||
Props
|
|
||||||
> &
|
> &
|
||||||
ComponentOptionsBase<
|
ComponentOptionsBase<
|
||||||
Props,
|
Props,
|
||||||
|
|
|
@ -15,7 +15,8 @@ import {
|
||||||
isString,
|
isString,
|
||||||
isFunction,
|
isFunction,
|
||||||
UnionToIntersection,
|
UnionToIntersection,
|
||||||
Prettify
|
Prettify,
|
||||||
|
IfAny
|
||||||
} from '@vue/shared'
|
} from '@vue/shared'
|
||||||
import {
|
import {
|
||||||
toRaw,
|
toRaw,
|
||||||
|
@ -187,7 +188,6 @@ export type CreateComponentPublicInstance<
|
||||||
I,
|
I,
|
||||||
S
|
S
|
||||||
>
|
>
|
||||||
|
|
||||||
// public properties exposed on the proxy, which is used as the render context
|
// public properties exposed on the proxy, which is used as the render context
|
||||||
// in templates (as `this` in the render option)
|
// in templates (as `this` in the render option)
|
||||||
export type ComponentPublicInstance<
|
export type ComponentPublicInstance<
|
||||||
|
@ -226,7 +226,7 @@ export type ComponentPublicInstance<
|
||||||
: (...args: any) => any,
|
: (...args: any) => any,
|
||||||
options?: WatchOptions
|
options?: WatchOptions
|
||||||
): WatchStopHandle
|
): WatchStopHandle
|
||||||
} & P &
|
} & IfAny<P, P, Omit<P, keyof ShallowUnwrapRef<B>>> &
|
||||||
ShallowUnwrapRef<B> &
|
ShallowUnwrapRef<B> &
|
||||||
UnwrapNestedRefs<D> &
|
UnwrapNestedRefs<D> &
|
||||||
ExtractComputedReturns<C> &
|
ExtractComputedReturns<C> &
|
||||||
|
|
Loading…
Reference in New Issue