Skip to content

Commit 151a8ad

Browse files
authored
fix(compiler-sfc): infer TSIntersectionType in defineProps (#7394)
1 parent 1b69d5f commit 151a8ad

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap

+1
Original file line numberDiff line numberDiff line change
@@ -1643,6 +1643,7 @@ export default /*#__PURE__*/_defineComponent({
16431643
literalUnionNumber: { type: Number, required: true },
16441644
literalUnionMixed: { type: [String, Number, Boolean], required: true },
16451645
intersection: { type: Object, required: true },
1646+
intersection2: { type: String, required: true },
16461647
foo: { type: [Function, null], required: true }
16471648
},
16481649
setup(__props: any, { expose }) {

packages/compiler-sfc/__tests__/compileScript.spec.ts

+3
Original file line numberDiff line numberDiff line change
@@ -972,6 +972,7 @@ const emit = defineEmits(['a', 'b'])
972972
literalUnionNumber: 1 | 2 | 3 | 4 | 5
973973
literalUnionMixed: 'foo' | 1 | boolean
974974
intersection: Test & {}
975+
intersection2: 'foo' & ('foo' | 'bar')
975976
foo: ((item: any) => boolean) | null
976977
}>()
977978
</script>`)
@@ -1014,6 +1015,7 @@ const emit = defineEmits(['a', 'b'])
10141015
`literalUnionMixed: { type: [String, Number, Boolean], required: true }`
10151016
)
10161017
expect(content).toMatch(`intersection: { type: Object, required: true }`)
1018+
expect(content).toMatch(`intersection2: { type: String, required: true }`)
10171019
expect(content).toMatch(`foo: { type: [Function, null], required: true }`)
10181020
expect(bindings).toStrictEqual({
10191021
string: BindingTypes.PROPS,
@@ -1044,6 +1046,7 @@ const emit = defineEmits(['a', 'b'])
10441046
literalUnionNumber: BindingTypes.PROPS,
10451047
literalUnionMixed: BindingTypes.PROPS,
10461048
intersection: BindingTypes.PROPS,
1049+
intersection2: BindingTypes.PROPS,
10471050
foo: BindingTypes.PROPS
10481051
})
10491052
})

packages/compiler-sfc/src/compileScript.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -2088,15 +2088,14 @@ function inferRuntimeType(
20882088
case 'TSParenthesizedType':
20892089
return inferRuntimeType(node.typeAnnotation, declaredTypes)
20902090
case 'TSUnionType':
2091+
case 'TSIntersectionType':
20912092
return [
20922093
...new Set(
20932094
[].concat(
20942095
...(node.types.map(t => inferRuntimeType(t, declaredTypes)) as any)
20952096
)
20962097
)
20972098
]
2098-
case 'TSIntersectionType':
2099-
return ['Object']
21002099

21012100
case 'TSSymbolKeyword':
21022101
return ['Symbol']

0 commit comments

Comments
 (0)