diff --git a/packages/runtime-core/__tests__/componentProps.spec.ts b/packages/runtime-core/__tests__/componentProps.spec.ts index b8eb0e47208..1fc019ff2a4 100644 --- a/packages/runtime-core/__tests__/componentProps.spec.ts +++ b/packages/runtime-core/__tests__/componentProps.spec.ts @@ -389,15 +389,24 @@ describe('component props', () => { bool: { type: Boolean, required: true }, str: { type: String, required: true }, num: { type: Number, required: true }, + null1: { type: null, required: true }, + null2: { type: null, required: true }, + null3: { type: null, required: true }, }, setup() { return () => null }, } - render(h(Comp), nodeOps.createElement('div')) + render( + h(Comp, { null2: null, null3: undefined }), + nodeOps.createElement('div'), + ) expect(`Missing required prop: "bool"`).toHaveBeenWarned() expect(`Missing required prop: "str"`).toHaveBeenWarned() expect(`Missing required prop: "num"`).toHaveBeenWarned() + expect(`Missing required prop: "null1"`).toHaveBeenWarned() + expect(`Missing required prop: "null2"`).toHaveBeenWarned() + expect(`Missing required prop: "null3"`).toHaveBeenWarned() }) test('warn on type mismatch', () => { diff --git a/packages/runtime-core/src/componentProps.ts b/packages/runtime-core/src/componentProps.ts index 8baa7808665..fce757cd41b 100644 --- a/packages/runtime-core/src/componentProps.ts +++ b/packages/runtime-core/src/componentProps.ts @@ -688,6 +688,11 @@ function validateProp( if (value == null && !required) { return } + // null type but required + if (type == null && required && value == null) { + warn('Missing required prop: "' + name + '"') + return + } // type check if (type != null && type !== true && !skipCheck) { let isValid = false