Skip to content

Commit

Permalink
fix(runtime-core): skip prop type check when null included
Browse files Browse the repository at this point in the history
  • Loading branch information
sxzz committed Jan 17, 2023
1 parent bef85e7 commit 85dec14
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
10 changes: 8 additions & 2 deletions packages/runtime-core/__tests__/componentProps.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,8 @@ describe('component props', () => {
arr: { type: Array },
obj: { type: Object },
cls: { type: MyClass },
fn: { type: Function }
fn: { type: Function },
fnAny: { type: [Function, null] }
},
setup() {
return () => null
Expand All @@ -345,7 +346,8 @@ describe('component props', () => {
arr: {},
obj: 'false',
cls: {},
fn: true
fn: true,
fnAny: true
}),
nodeOps.createElement('div')
)
Expand All @@ -370,6 +372,10 @@ describe('component props', () => {
expect(
`Invalid prop: type check failed for prop "cls". Expected MyClass, got Object`
).toHaveBeenWarned()

expect(
`Invalid prop: type check failed for prop "fnAny". Expected Function, got Boolean with value true.`
).not.toHaveBeenWarned()
})

// #3495
Expand Down
3 changes: 3 additions & 0 deletions packages/runtime-core/src/componentProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,9 @@ function validateProp(
if (type != null && type !== true) {
let isValid = false
const types = isArray(type) ? type : [type]
if (types.includes(null as any)) {
return
}
const expectedTypes = []
// value is valid as long as one of the specified types match
for (let i = 0; i < types.length && !isValid; i++) {
Expand Down

0 comments on commit 85dec14

Please sign in to comment.