]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(types): return type of withDefaults should be readonly (#8601)
authorzqran <215244947@qq.com>
Fri, 10 Nov 2023 07:20:02 +0000 (15:20 +0800)
committerGitHub <noreply@github.com>
Fri, 10 Nov 2023 07:20:02 +0000 (15:20 +0800)
packages/dts-test/setupHelpers.test-d.ts
packages/runtime-core/src/apiSetupHelpers.ts

index 838e376da2dee494958e5fa34f2f117d2d43e7d3..51f95c00944877bd3552c5d830815347b0639062 100644 (file)
@@ -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 }
@@ -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)
index cff0c6511e289606307138d1b3fc29e47d382610..509c280d63b5d8a05b17bb9b4e6c1067c5a50034 100644 (file)
@@ -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]>