fix(compiler-sfc): generate matching prop types when withDefaults is used (#4466)
fix #4455
This commit is contained in:
@@ -800,8 +800,11 @@ const emit = defineEmits(['a', 'b'])
|
||||
const props = withDefaults(defineProps<{
|
||||
foo?: string
|
||||
bar?: number
|
||||
baz: boolean
|
||||
qux?(): number
|
||||
}>(), {
|
||||
foo: 'hi'
|
||||
foo: 'hi',
|
||||
qux() { return 1 }
|
||||
})
|
||||
</script>
|
||||
`)
|
||||
@@ -810,10 +813,19 @@ const emit = defineEmits(['a', 'b'])
|
||||
`foo: { type: String, required: false, default: 'hi' }`
|
||||
)
|
||||
expect(content).toMatch(`bar: { type: Number, required: false }`)
|
||||
expect(content).toMatch(`baz: { type: Boolean, required: true }`)
|
||||
expect(content).toMatch(
|
||||
`qux: { type: Function, required: false, default() { return 1 } }`
|
||||
)
|
||||
expect(content).toMatch(
|
||||
`{ foo: string, bar?: number, baz: boolean, qux(): number }`
|
||||
)
|
||||
expect(content).toMatch(`const props = __props`)
|
||||
expect(bindings).toStrictEqual({
|
||||
foo: BindingTypes.PROPS,
|
||||
bar: BindingTypes.PROPS,
|
||||
baz: BindingTypes.PROPS,
|
||||
qux: BindingTypes.PROPS,
|
||||
props: BindingTypes.SETUP_CONST
|
||||
})
|
||||
})
|
||||
@@ -825,6 +837,7 @@ const emit = defineEmits(['a', 'b'])
|
||||
const props = withDefaults(defineProps<{
|
||||
foo?: string
|
||||
bar?: number
|
||||
baz: boolean
|
||||
}>(), { ...defaults })
|
||||
</script>
|
||||
`)
|
||||
@@ -834,7 +847,8 @@ const emit = defineEmits(['a', 'b'])
|
||||
`
|
||||
_mergeDefaults({
|
||||
foo: { type: String, required: false },
|
||||
bar: { type: Number, required: false }
|
||||
bar: { type: Number, required: false },
|
||||
baz: { type: Boolean, required: true }
|
||||
}, { ...defaults })`.trim()
|
||||
)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user