Skip to content

Commit

Permalink
fix(compiler-sfc): infer TSIntersectionType in defineProps (vuejs#7394)
Browse files Browse the repository at this point in the history
  • Loading branch information
sxzz authored and IAmSSH committed Apr 29, 2023
1 parent 4c78094 commit a8637ff
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) {
Expand Down
3 changes: 3 additions & 0 deletions packages/compiler-sfc/__tests__/compileScript.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>`)
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -1044,6 +1046,7 @@ const emit = defineEmits(['a', 'b'])
literalUnionNumber: BindingTypes.PROPS,
literalUnionMixed: BindingTypes.PROPS,
intersection: BindingTypes.PROPS,
intersection2: BindingTypes.PROPS,
foo: BindingTypes.PROPS
})
})
Expand Down
3 changes: 1 addition & 2 deletions packages/compiler-sfc/src/compileScript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2088,15 +2088,14 @@ function inferRuntimeType(
case 'TSParenthesizedType':
return inferRuntimeType(node.typeAnnotation, declaredTypes)
case 'TSUnionType':
case 'TSIntersectionType':
return [
...new Set(
[].concat(
...(node.types.map(t => inferRuntimeType(t, declaredTypes)) as any)
)
)
]
case 'TSIntersectionType':
return ['Object']

case 'TSSymbolKeyword':
return ['Symbol']
Expand Down

0 comments on commit a8637ff

Please sign in to comment.