fix(compiler-sfc): infer TSIntersectionType in defineProps (#7394)

This commit is contained in:
三咲智子 Kevin Deng 2023-03-28 15:40:03 +08:00 committed by GitHub
parent 1b69d5f2f4
commit 151a8ad6b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 2 deletions

View 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 }) {

View 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
})
})

View 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']