Skip to content
This repository was archived by the owner on Jul 19, 2025. It is now read-only.

Commit 96e4738

Browse files
committed
fix(types): respect props with default on instance type when using __typeProps
1 parent cd0ea0d commit 96e4738

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

packages/dts-test/defineComponent.test-d.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1972,3 +1972,24 @@ createApp({}).component(
19721972
},
19731973
}),
19741974
)
1975+
1976+
const Comp = defineComponent({
1977+
props: {
1978+
actionText: {
1979+
type: {} as PropType<string>,
1980+
default: 'Become a sponsor',
1981+
},
1982+
},
1983+
__typeProps: {} as {
1984+
actionText?: string
1985+
},
1986+
})
1987+
1988+
const instance = new Comp()
1989+
function expectString(s: string) {}
1990+
// instance prop with default should be non-null
1991+
expectString(instance.actionText)
1992+
1993+
// public prop on $props should be optional
1994+
// @ts-expect-error
1995+
expectString(instance.$props.actionText)

packages/runtime-core/src/componentPublicInstance.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ export type ComponentPublicInstance<
292292
C extends ComputedOptions = {},
293293
M extends MethodOptions = {},
294294
E extends EmitsOptions = {},
295-
PublicProps = P,
295+
PublicProps = {},
296296
Defaults = {},
297297
MakeDefaultsOptional extends boolean = false,
298298
Options = ComponentOptionsBase<any, any, any, any, any, any, any, any, any>,
@@ -323,7 +323,11 @@ export type ComponentPublicInstance<
323323
options?: WatchOptions,
324324
): WatchStopHandle
325325
} & ExposedKeys<
326-
IfAny<P, P, Omit<P, keyof ShallowUnwrapRef<B>>> &
326+
IfAny<
327+
P,
328+
P,
329+
Readonly<Defaults> & Omit<P, keyof ShallowUnwrapRef<B> | keyof Defaults>
330+
> &
327331
ShallowUnwrapRef<B> &
328332
UnwrapNestedRefs<D> &
329333
ExtractComputedReturns<C> &

0 commit comments

Comments
 (0)