fix(compiler-sfc): defineProps infer TSParenthesizedType (#4147)
This commit is contained in:
parent
47ba33e27b
commit
f7607d3a15
@ -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()
|
||||
|
||||
|
@ -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
|
||||
})
|
||||
})
|
||||
|
||||
|
@ -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']
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user