diff --git a/packages/compiler-sfc/__tests__/__snapshots__/compileScriptPropsTransform.spec.ts.snap b/packages/compiler-sfc/__tests__/__snapshots__/compileScriptPropsTransform.spec.ts.snap index a8f95c72a13..f85b2db9b9f 100644 --- a/packages/compiler-sfc/__tests__/__snapshots__/compileScriptPropsTransform.spec.ts.snap +++ b/packages/compiler-sfc/__tests__/__snapshots__/compileScriptPropsTransform.spec.ts.snap @@ -80,9 +80,10 @@ exports[`sfc props transform default values w/ type declaration, prod mode 1`] = export default /*#__PURE__*/_defineComponent({ props: { - foo: { default: 1 }, - bar: { default: () => {} }, - baz: null + foo: { type: Number, default: 1 }, + bar: { type: Object, default: () => {} }, + baz: { type: null }, + bool: { type: Boolean } }, setup(__props: any) { diff --git a/packages/compiler-sfc/__tests__/compileScriptPropsTransform.spec.ts b/packages/compiler-sfc/__tests__/compileScriptPropsTransform.spec.ts index f388e501dd9..e8fc9039f55 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 } @@ -91,9 +91,10 @@ describe('sfc props transform', () => { // literals can be used as-is, non-literals are always returned from a // function expect(content).toMatch(`props: { - foo: { default: 1 }, - bar: { default: () => {} }, - baz: null + foo: { type: Number, default: 1 }, + bar: { type: Object, default: () => {} }, + baz: { type: null }, + bool: { type: Boolean } }`) assertCode(content) }) diff --git a/packages/compiler-sfc/src/compileScript.ts b/packages/compiler-sfc/src/compileScript.ts index 0e60d0d9e31..9a4ac1979f7 100644 --- a/packages/compiler-sfc/src/compileScript.ts +++ b/packages/compiler-sfc/src/compileScript.ts @@ -693,8 +693,13 @@ export function compileScript( defaultString ? `, ${defaultString}` : `` } }` } else { + const { type } = props[key] // production: checks are useless - return `${key}: ${defaultString ? `{ ${defaultString} }` : 'null'}` + return `${key}: { type: ${toRuntimeTypeString( + type + )}${ + defaultString ? `, ${defaultString}` : `` + } }` } }) .join(',\n ')}\n }` @@ -1621,15 +1626,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,