fix(compiler-sfc): defineProps infer TSParenthesizedType (#4147)

This commit is contained in:
edison 2021-07-19 23:09:24 +08:00 committed by GitHub
parent 47ba33e27b
commit f7607d3a15
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 3 deletions

View File

@ -761,7 +761,8 @@ export default _defineComponent({
union: { type: [String, Number], required: true }, union: { type: [String, Number], required: true },
literalUnion: { type: [String, String], required: true }, literalUnion: { type: [String, String], required: true },
literalUnionMixed: { type: [String, Number, Boolean], 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, } as unknown as undefined,
setup(__props: { setup(__props: {
string: string string: string
@ -787,6 +788,7 @@ export default _defineComponent({
literalUnion: 'foo' | 'bar' literalUnion: 'foo' | 'bar'
literalUnionMixed: 'foo' | 1 | boolean literalUnionMixed: 'foo' | 1 | boolean
intersection: Test & {} intersection: Test & {}
foo: ((item: any) => boolean) | null
}, { expose }) { }, { expose }) {
expose() expose()

View File

@ -514,6 +514,7 @@ const emit = defineEmits(['a', 'b'])
literalUnion: 'foo' | 'bar' literalUnion: 'foo' | 'bar'
literalUnionMixed: 'foo' | 1 | boolean literalUnionMixed: 'foo' | 1 | boolean
intersection: Test & {} intersection: Test & {}
foo: ((item: any) => boolean) | null
}>() }>()
</script>`) </script>`)
assertCode(content) assertCode(content)
@ -545,6 +546,7 @@ const emit = defineEmits(['a', 'b'])
`literalUnionMixed: { type: [String, Number, Boolean], required: true }` `literalUnionMixed: { type: [String, Number, Boolean], required: true }`
) )
expect(content).toMatch(`intersection: { type: Object, required: true }`) expect(content).toMatch(`intersection: { type: Object, required: true }`)
expect(content).toMatch(`foo: { type: [Function, null], required: true }`)
expect(bindings).toStrictEqual({ expect(bindings).toStrictEqual({
string: BindingTypes.PROPS, string: BindingTypes.PROPS,
number: BindingTypes.PROPS, number: BindingTypes.PROPS,
@ -567,7 +569,8 @@ const emit = defineEmits(['a', 'b'])
union: BindingTypes.PROPS, union: BindingTypes.PROPS,
literalUnion: BindingTypes.PROPS, literalUnion: BindingTypes.PROPS,
literalUnionMixed: BindingTypes.PROPS, literalUnionMixed: BindingTypes.PROPS,
intersection: BindingTypes.PROPS intersection: BindingTypes.PROPS,
foo: BindingTypes.PROPS
}) })
}) })

View File

@ -1646,6 +1646,8 @@ function inferRuntimeType(
} }
return [`null`] return [`null`]
case 'TSParenthesizedType':
return inferRuntimeType(node.typeAnnotation, declaredTypes)
case 'TSUnionType': case 'TSUnionType':
return [ return [
...new Set( ...new Set(
@ -1654,7 +1656,6 @@ function inferRuntimeType(
) as any) ) as any)
) )
] ]
case 'TSIntersectionType': case 'TSIntersectionType':
return ['Object'] return ['Object']