]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(type): fix prop type infer (#4530)
authorfishDog <40156382+Bigfish8@users.noreply.github.com>
Mon, 6 Sep 2021 19:24:15 +0000 (03:24 +0800)
committerGitHub <noreply@github.com>
Mon, 6 Sep 2021 19:24:15 +0000 (15:24 -0400)
fix #4525

packages/runtime-core/src/componentProps.ts
test-dts/defineComponent.test-d.tsx

index cca7fbcdc72734471b0bba06047e032ac8b18e69..924f40a7384cf87a410391ee3ffc2bf12e6fcc14 100644 (file)
@@ -109,10 +109,10 @@ type InferPropType<T> = [T] extends [null]
   ? boolean
   : [T] extends [DateConstructor | { type: DateConstructor }]
   ? Date
-  : [T] extends [
-      (DateConstructor | infer U)[] | { type: (DateConstructor | infer U)[] }
-    ]
-  ? Date | InferPropType<U>
+  : [T] extends [(infer U)[] | { type: (infer U)[] }]
+  ? U extends DateConstructor
+    ? Date | InferPropType<U>
+    : InferPropType<U>
   : [T] extends [Prop<infer V, infer D>]
   ? unknown extends V
     ? D
index fb50648b579b87871f7e138831ad8f2a81184108..8604f8e9fbd30b38f42e19e21927ae832e603c1a 100644 (file)
@@ -44,6 +44,7 @@ describe('with object props', () => {
     date?: Date
     l?: Date
     ll?: Date | number
+    lll?: string | number
   }
 
   type GT = string & { __brand: unknown }
@@ -135,7 +136,8 @@ describe('with object props', () => {
       },
       date: Date,
       l: [Date],
-      ll: [Date, Number]
+      ll: [Date, Number],
+      lll: [String, Number]
     },
     setup(props) {
       // type assertion. See https://github.com/SamVerschueren/tsd
@@ -170,6 +172,7 @@ describe('with object props', () => {
       expectType<ExpectedProps['date']>(props.date)
       expectType<ExpectedProps['l']>(props.l)
       expectType<ExpectedProps['ll']>(props.ll)
+      expectType<ExpectedProps['lll']>(props.lll)
 
       // @ts-expect-error props should be readonly
       expectError((props.a = 1))