Skip to content

Change prop type checking to use instanceof instead of typeof #6447

@DanielCoulbourne

Description

@DanielCoulbourne

What problem does this feature solve?

Currently prop type checking fails when passing in an object that extends the expected type.
This would allow anything inheriting from the expected type to pass the check.

What does the proposed API look like?

valid = typeof value === expectedType.toLowerCase()

If this line were

valid = value instanceof expectedType.toLowerCase()

Then child classes would also pass. In my mind if a component is checking for String and I pass in an object that extends string this should pass the typecheck.

This was born out of an issue that one of my users has passing an String castable object which extends string as a prop into a Vue component.

If you're interested you can check that out here:

tighten/ziggy#64

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions