Skip to content

Commit f7607d3

Browse files
authored
fix(compiler-sfc): defineProps infer TSParenthesizedType (#4147)
1 parent 47ba33e commit f7607d3

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,8 @@ export default _defineComponent({
761761
union: { type: [String, Number], required: true },
762762
literalUnion: { type: [String, String], required: true },
763763
literalUnionMixed: { type: [String, Number, Boolean], required: true },
764-
intersection: { type: Object, required: true }
764+
intersection: { type: Object, required: true },
765+
foo: { type: [Function, null], required: true }
765766
} as unknown as undefined,
766767
setup(__props: {
767768
string: string
@@ -787,6 +788,7 @@ export default _defineComponent({
787788
literalUnion: 'foo' | 'bar'
788789
literalUnionMixed: 'foo' | 1 | boolean
789790
intersection: Test & {}
791+
foo: ((item: any) => boolean) | null
790792
}, { expose }) {
791793
expose()
792794

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

+4-1
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,7 @@ const emit = defineEmits(['a', 'b'])
514514
literalUnion: 'foo' | 'bar'
515515
literalUnionMixed: 'foo' | 1 | boolean
516516
intersection: Test & {}
517+
foo: ((item: any) => boolean) | null
517518
}>()
518519
</script>`)
519520
assertCode(content)
@@ -545,6 +546,7 @@ const emit = defineEmits(['a', 'b'])
545546
`literalUnionMixed: { type: [String, Number, Boolean], required: true }`
546547
)
547548
expect(content).toMatch(`intersection: { type: Object, required: true }`)
549+
expect(content).toMatch(`foo: { type: [Function, null], required: true }`)
548550
expect(bindings).toStrictEqual({
549551
string: BindingTypes.PROPS,
550552
number: BindingTypes.PROPS,
@@ -567,7 +569,8 @@ const emit = defineEmits(['a', 'b'])
567569
union: BindingTypes.PROPS,
568570
literalUnion: BindingTypes.PROPS,
569571
literalUnionMixed: BindingTypes.PROPS,
570-
intersection: BindingTypes.PROPS
572+
intersection: BindingTypes.PROPS,
573+
foo: BindingTypes.PROPS
571574
})
572575
})
573576

packages/compiler-sfc/src/compileScript.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1646,6 +1646,8 @@ function inferRuntimeType(
16461646
}
16471647
return [`null`]
16481648

1649+
case 'TSParenthesizedType':
1650+
return inferRuntimeType(node.typeAnnotation, declaredTypes)
16491651
case 'TSUnionType':
16501652
return [
16511653
...new Set(
@@ -1654,7 +1656,6 @@ function inferRuntimeType(
16541656
) as any)
16551657
)
16561658
]
1657-
16581659
case 'TSIntersectionType':
16591660
return ['Object']
16601661

0 commit comments

Comments
 (0)