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): props type is incompatible with setup returned type #7338

Merged
merged 2 commits into from
Nov 9, 2023
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
25 changes: 25 additions & 0 deletions packages/dts-test/defineComponent.test-d.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1472,6 +1472,31 @@ describe('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 {
DefineComponent,
ComponentOptionsMixin,
Expand Down
3 changes: 1 addition & 2 deletions packages/runtime-core/src/apiDefineComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ export type DefineComponent<
true,
{},
S
> &
Props
>
> &
ComponentOptionsBase<
Props,
Expand Down
6 changes: 3 additions & 3 deletions packages/runtime-core/src/componentPublicInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import {
isString,
isFunction,
UnionToIntersection,
Prettify
Prettify,
IfAny
} from '@vue/shared'
import {
toRaw,
Expand Down Expand Up @@ -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<
Expand Down Expand Up @@ -228,7 +228,7 @@ export type ComponentPublicInstance<
: (...args: any) => any,
options?: WatchOptions
): WatchStopHandle
} & P &
} & IfAny<P, P, Omit<P, keyof ShallowUnwrapRef<B>>> &
ShallowUnwrapRef<B> &
UnwrapNestedRefs<D> &
ExtractComputedReturns<C> &
Expand Down
Loading