fix(compiler-sfc): add type for props's properties in prod mode (#4790)

fix #4783
This commit is contained in:
ygj6
2021-11-03 10:04:04 +08:00
committed by GitHub
parent d56f115f71
commit 090df0837e
3 changed files with 22 additions and 13 deletions

View File

@@ -685,13 +685,20 @@ export function compileScript(
}
}
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'}`
@@ -1621,15 +1628,13 @@ function extractRuntimeProps(
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,