diff --git a/packages/dts-test/defineComponent.test-d.tsx b/packages/dts-test/defineComponent.test-d.tsx index 7466249e10f..b3f735ddad9 100644 --- a/packages/dts-test/defineComponent.test-d.tsx +++ b/packages/dts-test/defineComponent.test-d.tsx @@ -1472,6 +1472,31 @@ describe('slots', () => { expectType(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, + required: true + } + }, + setup(props) { + expectType(props.size) + return { + size: 1 + } + } + }) + type CompInstance = InstanceType + + const CompA = {} as CompInstance + expectType(CompA) + expectType(CompA.size) + expectType(CompA.$props.size) +}) + import { DefineComponent, ComponentOptionsMixin, diff --git a/packages/runtime-core/src/apiDefineComponent.ts b/packages/runtime-core/src/apiDefineComponent.ts index 272bb548751..092f679e966 100644 --- a/packages/runtime-core/src/apiDefineComponent.ts +++ b/packages/runtime-core/src/apiDefineComponent.ts @@ -70,8 +70,7 @@ export type DefineComponent< true, {}, S - > & - Props + > > & ComponentOptionsBase< Props, diff --git a/packages/runtime-core/src/componentPublicInstance.ts b/packages/runtime-core/src/componentPublicInstance.ts index dc575aafff9..21365573f11 100644 --- a/packages/runtime-core/src/componentPublicInstance.ts +++ b/packages/runtime-core/src/componentPublicInstance.ts @@ -15,7 +15,8 @@ import { isString, isFunction, UnionToIntersection, - Prettify + Prettify, + IfAny } from '@vue/shared' import { toRaw, @@ -187,7 +188,6 @@ export type CreateComponentPublicInstance< I, S > - // public properties exposed on the proxy, which is used as the render context // in templates (as `this` in the render option) export type ComponentPublicInstance< @@ -228,7 +228,7 @@ export type ComponentPublicInstance< : (...args: any) => any, options?: WatchOptions ): WatchStopHandle -} & P & +} & IfAny>> & ShallowUnwrapRef & UnwrapNestedRefs & ExtractComputedReturns &