fix(defineProps): defineProps generates unnecessary array of same types (#4353)
fix #4352
This commit is contained in:
parent
77223df2d2
commit
ad66295cb3
@ -790,7 +790,8 @@ export default _defineComponent({
|
|||||||
alias: { type: Array, required: true },
|
alias: { type: Array, required: true },
|
||||||
method: { type: Function, required: true },
|
method: { type: Function, required: true },
|
||||||
union: { type: [String, Number], required: true },
|
union: { type: [String, Number], required: true },
|
||||||
literalUnion: { type: [String, String], required: true },
|
literalUnion: { type: String, required: true },
|
||||||
|
literalUnionNumber: { type: Number, 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 }
|
foo: { type: [Function, null], required: true }
|
||||||
@ -817,6 +818,7 @@ export default _defineComponent({
|
|||||||
|
|
||||||
union: string | number
|
union: string | number
|
||||||
literalUnion: 'foo' | 'bar'
|
literalUnion: 'foo' | 'bar'
|
||||||
|
literalUnionNumber: 1 | 2 | 3 | 4 | 5
|
||||||
literalUnionMixed: 'foo' | 1 | boolean
|
literalUnionMixed: 'foo' | 1 | boolean
|
||||||
intersection: Test & {}
|
intersection: Test & {}
|
||||||
foo: ((item: any) => boolean) | null
|
foo: ((item: any) => boolean) | null
|
||||||
|
@ -538,6 +538,7 @@ const emit = defineEmits(['a', 'b'])
|
|||||||
|
|
||||||
union: string | number
|
union: string | number
|
||||||
literalUnion: 'foo' | 'bar'
|
literalUnion: 'foo' | 'bar'
|
||||||
|
literalUnionNumber: 1 | 2 | 3 | 4 | 5
|
||||||
literalUnionMixed: 'foo' | 1 | boolean
|
literalUnionMixed: 'foo' | 1 | boolean
|
||||||
intersection: Test & {}
|
intersection: Test & {}
|
||||||
foo: ((item: any) => boolean) | null
|
foo: ((item: any) => boolean) | null
|
||||||
@ -565,8 +566,9 @@ const emit = defineEmits(['a', 'b'])
|
|||||||
expect(content).toMatch(
|
expect(content).toMatch(
|
||||||
`union: { type: [String, Number], required: true }`
|
`union: { type: [String, Number], required: true }`
|
||||||
)
|
)
|
||||||
|
expect(content).toMatch(`literalUnion: { type: String, required: true }`)
|
||||||
expect(content).toMatch(
|
expect(content).toMatch(
|
||||||
`literalUnion: { type: [String, String], required: true }`
|
`literalUnionNumber: { type: Number, required: true }`
|
||||||
)
|
)
|
||||||
expect(content).toMatch(
|
expect(content).toMatch(
|
||||||
`literalUnionMixed: { type: [String, Number, Boolean], required: true }`
|
`literalUnionMixed: { type: [String, Number, Boolean], required: true }`
|
||||||
@ -594,6 +596,7 @@ const emit = defineEmits(['a', 'b'])
|
|||||||
method: BindingTypes.PROPS,
|
method: BindingTypes.PROPS,
|
||||||
union: BindingTypes.PROPS,
|
union: BindingTypes.PROPS,
|
||||||
literalUnion: BindingTypes.PROPS,
|
literalUnion: BindingTypes.PROPS,
|
||||||
|
literalUnionNumber: BindingTypes.PROPS,
|
||||||
literalUnionMixed: BindingTypes.PROPS,
|
literalUnionMixed: BindingTypes.PROPS,
|
||||||
intersection: BindingTypes.PROPS,
|
intersection: BindingTypes.PROPS,
|
||||||
foo: BindingTypes.PROPS
|
foo: BindingTypes.PROPS
|
||||||
|
@ -1703,7 +1703,7 @@ function inferRuntimeType(
|
|||||||
return [
|
return [
|
||||||
...new Set(
|
...new Set(
|
||||||
[].concat(
|
[].concat(
|
||||||
node.types.map(t => inferRuntimeType(t, declaredTypes)) as any
|
...(node.types.map(t => inferRuntimeType(t, declaredTypes)) as any)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
@ -1716,11 +1716,7 @@ function inferRuntimeType(
|
|||||||
}
|
}
|
||||||
|
|
||||||
function toRuntimeTypeString(types: string[]) {
|
function toRuntimeTypeString(types: string[]) {
|
||||||
return types.some(t => t === 'null')
|
return types.length > 1 ? `[${types.join(', ')}]` : types[0]
|
||||||
? `null`
|
|
||||||
: types.length > 1
|
|
||||||
? `[${types.join(', ')}]`
|
|
||||||
: types[0]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function extractRuntimeEmits(
|
function extractRuntimeEmits(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user