bar: { default: () => {} },
baz: null,
boola: { type: Boolean },
- boolb: { type: [Boolean, Number] }
+ boolb: { type: [Boolean, Number] },
+ func: { type: Function, default: () => () => {} }
},
setup(__props: any) {
const { content } = compile(
`
<script setup lang="ts">
- const { foo = 1, bar = {} } = defineProps<{ foo?: number, bar?: object, baz?: any, boola?: boolean, boolb?: boolean | number }>()
+ const { foo = 1, bar = {}, func = () => {} } = defineProps<{ foo?: number, bar?: object, baz?: any, boola?: boolean, boolb?: boolean | number, func?: Function }>()
</script>
`,
{ isProd: true }
bar: { default: () => {} },
baz: null,
boola: { type: Boolean },
- boolb: { type: [Boolean, Number] }
+ boolb: { type: [Boolean, Number] },
+ func: { type: Function, default: () => () => {} }
}`)
assertCode(content)
})
)}, required: ${required}${
defaultString ? `, ${defaultString}` : ``
} }`
- } else if (type.indexOf('Boolean') > -1) {
- // production: if boolean exists, should keep the type.
- return `${key}: { type: ${toRuntimeTypeString(
- type
- )}${
+ } else if (
+ type.some(
+ el => el === 'Boolean' || (defaultString && el === 'Function')
+ )
+ ) {
+ // #4783 production: if boolean or defaultString and function exists, should keep the type.
+ return `${key}: { type: ${toRuntimeTypeString(type)}${
defaultString ? `, ${defaultString}` : ``
} }`
} else {
if (m.type === 'TSMethodSignature') {
type = ['Function']
} else if (m.typeAnnotation) {
- type = inferRuntimeType(
- m.typeAnnotation.typeAnnotation,
- declaredTypes
- )
+ type = inferRuntimeType(m.typeAnnotation.typeAnnotation, declaredTypes)
}
props[m.key.name] = {
key: m.key.name,