Skip to content

Commit

Permalink
fix(types): return type of withDefaults should be readonly (#8601)
Browse files Browse the repository at this point in the history
  • Loading branch information
zqran authored Nov 10, 2023
1 parent 46e3374 commit f15debc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 5 additions & 0 deletions packages/dts-test/setupHelpers.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ describe('defineProps w/ generic type declaration + withDefaults', <T extends
defineProps<{
n?: number
bool?: boolean
s?: string

generic1?: T[] | { x: T }
generic2?: { x: T }
Expand All @@ -128,6 +129,10 @@ describe('defineProps w/ generic type declaration + withDefaults', <T extends
)

res.n + 1
// @ts-expect-error should be readonly
res.n++
// @ts-expect-error should be readonly
res.s = ''

expectType<T[] | { x: T }>(res.generic1)
expectType<{ x: T }>(res.generic2)
Expand Down
4 changes: 2 additions & 2 deletions packages/runtime-core/src/apiSetupHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,8 @@ type PropsWithDefaults<
T,
Defaults extends InferDefaults<T>,
BKeys extends keyof T
> = Omit<T, keyof Defaults> & {
[K in keyof Defaults]-?: K extends keyof T
> = Readonly<Omit<T, keyof Defaults>> & {
readonly [K in keyof Defaults]-?: K extends keyof T
? Defaults[K] extends undefined
? T[K]
: NotUndefined<T[K]>
Expand Down

0 comments on commit f15debc

Please sign in to comment.