diff --git a/packages/compiler-sfc/__tests__/__snapshots__/compileScriptPropsTransform.spec.ts.snap b/packages/compiler-sfc/__tests__/__snapshots__/compileScriptPropsTransform.spec.ts.snap index a8f95c72a13..5b11ae5c1a5 100644 --- a/packages/compiler-sfc/__tests__/__snapshots__/compileScriptPropsTransform.spec.ts.snap +++ b/packages/compiler-sfc/__tests__/__snapshots__/compileScriptPropsTransform.spec.ts.snap @@ -82,7 +82,9 @@ export default /*#__PURE__*/_defineComponent({ props: { foo: { default: 1 }, bar: { default: () => {} }, - baz: null + baz: null, + boola: { type: Boolean }, + boolb: { type: [Boolean, Number] } }, setup(__props: any) { diff --git a/packages/compiler-sfc/__tests__/compileScriptPropsTransform.spec.ts b/packages/compiler-sfc/__tests__/compileScriptPropsTransform.spec.ts index f388e501dd9..5d406608288 100644 --- a/packages/compiler-sfc/__tests__/compileScriptPropsTransform.spec.ts +++ b/packages/compiler-sfc/__tests__/compileScriptPropsTransform.spec.ts @@ -83,7 +83,7 @@ describe('sfc props transform', () => { const { content } = compile( ` `, { isProd: true } @@ -93,7 +93,9 @@ describe('sfc props transform', () => { expect(content).toMatch(`props: { foo: { default: 1 }, bar: { default: () => {} }, - baz: null + baz: null, + boola: { type: Boolean }, + boolb: { type: [Boolean, Number] } }`) assertCode(content) }) diff --git a/packages/compiler-sfc/src/compileScript.ts b/packages/compiler-sfc/src/compileScript.ts index 0e60d0d9e31..dcaf3848caa 100644 --- a/packages/compiler-sfc/src/compileScript.ts +++ b/packages/compiler-sfc/src/compileScript.ts @@ -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,