]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(compiler-sfc): infer TSIntersectionType in defineProps (#7394)
author三咲智子 Kevin Deng <sxzz@sxzz.moe>
Tue, 28 Mar 2023 07:40:03 +0000 (15:40 +0800)
committerGitHub <noreply@github.com>
Tue, 28 Mar 2023 07:40:03 +0000 (15:40 +0800)
packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap
packages/compiler-sfc/__tests__/compileScript.spec.ts
packages/compiler-sfc/src/compileScript.ts

index 05e5e4fd1fd0e919f2055229a068ab84eb4b47be..9018df65a1822c83cbbfe09664c810b54cde4d0c 100644 (file)
@@ -1643,6 +1643,7 @@ export default /*#__PURE__*/_defineComponent({
     literalUnionNumber: { type: Number, required: true },
     literalUnionMixed: { type: [String, Number, Boolean], required: true },
     intersection: { type: Object, required: true },
+    intersection2: { type: String, required: true },
     foo: { type: [Function, null], required: true }
   },
   setup(__props: any, { expose }) {
index 9c3c4a7027388ab3a35ce5024925ab9f9edfd46d..10eeea0167435557704707f54726454731d68044 100644 (file)
@@ -972,6 +972,7 @@ const emit = defineEmits(['a', 'b'])
         literalUnionNumber: 1 | 2 | 3 | 4 | 5
         literalUnionMixed: 'foo' | 1 | boolean
         intersection: Test & {}
+        intersection2: 'foo' & ('foo' | 'bar')
         foo: ((item: any) => boolean) | null
       }>()
       </script>`)
@@ -1014,6 +1015,7 @@ const emit = defineEmits(['a', 'b'])
         `literalUnionMixed: { type: [String, Number, Boolean], required: true }`
       )
       expect(content).toMatch(`intersection: { type: Object, required: true }`)
+      expect(content).toMatch(`intersection2: { type: String, required: true }`)
       expect(content).toMatch(`foo: { type: [Function, null], required: true }`)
       expect(bindings).toStrictEqual({
         string: BindingTypes.PROPS,
@@ -1044,6 +1046,7 @@ const emit = defineEmits(['a', 'b'])
         literalUnionNumber: BindingTypes.PROPS,
         literalUnionMixed: BindingTypes.PROPS,
         intersection: BindingTypes.PROPS,
+        intersection2: BindingTypes.PROPS,
         foo: BindingTypes.PROPS
       })
     })
index 1b13c90b6eefaacf71ea6e0612b5c14a56d28b7d..922351d9d45a4bbad33550a9c5eb5428d8f31292 100644 (file)
@@ -2088,6 +2088,7 @@ function inferRuntimeType(
     case 'TSParenthesizedType':
       return inferRuntimeType(node.typeAnnotation, declaredTypes)
     case 'TSUnionType':
+    case 'TSIntersectionType':
       return [
         ...new Set(
           [].concat(
@@ -2095,8 +2096,6 @@ function inferRuntimeType(
           )
         )
       ]
-    case 'TSIntersectionType':
-      return ['Object']
 
     case 'TSSymbolKeyword':
       return ['Symbol']