const { content } = compile(
`
<script setup lang="ts">
- const { foo = 1, bar = {} } = defineProps<{ foo?: number, bar?: object, baz?: any }>()
+ const { foo = 1, bar = {} } = defineProps<{ foo?: number, bar?: object, baz?: any, boola?: boolean, boolb?: boolean | number }>()
</script>
`,
{ isProd: true }
expect(content).toMatch(`props: {
foo: { default: 1 },
bar: { default: () => {} },
- baz: null
+ baz: null,
+ boola: { type: Boolean },
+ boolb: { type: [Boolean, Number] }
}`)
assertCode(content)
})
}
}
+ const { type, required } = props[key]
if (!isProd) {
- const { type, required } = props[key]
return `${key}: { type: ${toRuntimeTypeString(
type
)}, required: ${required}${
defaultString ? `, ${defaultString}` : ``
} }`
+ } else if (type.indexOf('Boolean') > -1) {
+ // production: if boolean exists, should keep the type.
+ return `${key}: { type: ${toRuntimeTypeString(
+ type
+ )}${
+ defaultString ? `, ${defaultString}` : ``
+ } }`
} else {
// production: checks are useless
return `${key}: ${defaultString ? `{ ${defaultString} }` : 'null'}`
m.key.type === 'Identifier'
) {
let type
- if (!isProd) {
- if (m.type === 'TSMethodSignature') {
- type = ['Function']
- } else if (m.typeAnnotation) {
- type = inferRuntimeType(
- m.typeAnnotation.typeAnnotation,
- declaredTypes
- )
- }
+ if (m.type === 'TSMethodSignature') {
+ type = ['Function']
+ } else if (m.typeAnnotation) {
+ type = inferRuntimeType(
+ m.typeAnnotation.typeAnnotation,
+ declaredTypes
+ )
}
props[m.key.name] = {
key: m.key.name,