]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(compiler-sfc): defineProps infer TSParenthesizedType (#4147)
authoredison <daiwei521@126.com>
Mon, 19 Jul 2021 15:09:24 +0000 (23:09 +0800)
committerGitHub <noreply@github.com>
Mon, 19 Jul 2021 15:09:24 +0000 (11:09 -0400)
packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap
packages/compiler-sfc/__tests__/compileScript.spec.ts
packages/compiler-sfc/src/compileScript.ts

index a9a6f236778a041303a954308950c27f0507f9dc..d71f41b80023ab3052ddf518d49dabcaa8411391 100644 (file)
@@ -761,7 +761,8 @@ export default _defineComponent({
     union: { type: [String, Number], required: true },
     literalUnion: { type: [String, String], required: true },
     literalUnionMixed: { type: [String, Number, Boolean], required: true },
-    intersection: { type: Object, required: true }
+    intersection: { type: Object, required: true },
+    foo: { type: [Function, null], required: true }
   } as unknown as undefined,
   setup(__props: {
         string: string
@@ -787,6 +788,7 @@ export default _defineComponent({
         literalUnion: 'foo' | 'bar'
         literalUnionMixed: 'foo' | 1 | boolean
         intersection: Test & {}
+        foo: ((item: any) => boolean) | null
       }, { expose }) {
   expose()
 
index 42cb84f97fb2b6338fd47e1c4c715612c8c84791..4b701bf373e4b8f307de9a62439869839107c960 100644 (file)
@@ -514,6 +514,7 @@ const emit = defineEmits(['a', 'b'])
         literalUnion: 'foo' | 'bar'
         literalUnionMixed: 'foo' | 1 | boolean
         intersection: Test & {}
+        foo: ((item: any) => boolean) | null
       }>()
       </script>`)
       assertCode(content)
@@ -545,6 +546,7 @@ const emit = defineEmits(['a', 'b'])
         `literalUnionMixed: { type: [String, Number, Boolean], required: true }`
       )
       expect(content).toMatch(`intersection: { type: Object, required: true }`)
+      expect(content).toMatch(`foo: { type: [Function, null], required: true }`)
       expect(bindings).toStrictEqual({
         string: BindingTypes.PROPS,
         number: BindingTypes.PROPS,
@@ -567,7 +569,8 @@ const emit = defineEmits(['a', 'b'])
         union: BindingTypes.PROPS,
         literalUnion: BindingTypes.PROPS,
         literalUnionMixed: BindingTypes.PROPS,
-        intersection: BindingTypes.PROPS
+        intersection: BindingTypes.PROPS,
+        foo: BindingTypes.PROPS
       })
     })
 
index 05b8c8a50b07d438c6f1d77ef5f30ba191681d1a..0aab4d2855e6d4352014fa48dad3f9e2a218b69e 100644 (file)
@@ -1646,6 +1646,8 @@ function inferRuntimeType(
       }
       return [`null`]
 
+    case 'TSParenthesizedType':
+      return inferRuntimeType(node.typeAnnotation, declaredTypes)
     case 'TSUnionType':
       return [
         ...new Set(
@@ -1654,7 +1656,6 @@ function inferRuntimeType(
           ) as any)
         )
       ]
-
     case 'TSIntersectionType':
       return ['Object']