Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions packages/runtime-core/src/componentProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -737,14 +737,19 @@ function assertType(
valid = t === expectedType.toLowerCase()
// for primitive wrapper objects
if (!valid && t === 'object') {
valid = value instanceof (type as PropConstructor)
// Guard against invalid prop type definitions (e.g. 'object', {}, etc.)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The proper fix should be to avoid calling assertType if type is a null-lish value (at line:700)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The proper fix should be to avoid calling assertType if type is a null-lish value (at line:700)

Sorry, I misunderstood the meaning. I'll fix it right now

// Only attempt instanceof when the provided type is a function/constructor.
valid = isFunction(type) && value instanceof (type as PropConstructor)
}
} else if (expectedType === 'Object') {
valid = isObject(value)
} else if (expectedType === 'Array') {
valid = isArray(value)
} else {
valid = value instanceof (type as PropConstructor)
// Fallback to constructor check only when type is a function.
// This avoids errors like "Right-hand side of 'instanceof' is not an object"
// when users mistakenly pass invalid values (e.g. strings) in prop type.
valid = isFunction(type) && value instanceof (type as PropConstructor)
}
return {
valid,
Expand Down