fix(types): respect props with default on instance type when using __typeProps

This commit is contained in:
Evan You 2024-06-05 14:19:31 +08:00
parent cd0ea0d479
commit 96e4738334
No known key found for this signature in database
GPG Key ID: B9D421896CA450FB
2 changed files with 27 additions and 2 deletions

View File

@ -1972,3 +1972,24 @@ createApp({}).component(
},
}),
)
const Comp = defineComponent({
props: {
actionText: {
type: {} as PropType<string>,
default: 'Become a sponsor',
},
},
__typeProps: {} as {
actionText?: string
},
})
const instance = new Comp()
function expectString(s: string) {}
// instance prop with default should be non-null
expectString(instance.actionText)
// public prop on $props should be optional
// @ts-expect-error
expectString(instance.$props.actionText)

View File

@ -292,7 +292,7 @@ export type ComponentPublicInstance<
C extends ComputedOptions = {},
M extends MethodOptions = {},
E extends EmitsOptions = {},
PublicProps = P,
PublicProps = {},
Defaults = {},
MakeDefaultsOptional extends boolean = false,
Options = ComponentOptionsBase<any, any, any, any, any, any, any, any, any>,
@ -323,7 +323,11 @@ export type ComponentPublicInstance<
options?: WatchOptions,
): WatchStopHandle
} & ExposedKeys<
IfAny<P, P, Omit<P, keyof ShallowUnwrapRef<B>>> &
IfAny<
P,
P,
Readonly<Defaults> & Omit<P, keyof ShallowUnwrapRef<B> | keyof Defaults>
> &
ShallowUnwrapRef<B> &
UnwrapNestedRefs<D> &
ExtractComputedReturns<C> &