Skip to content

The left-hand side of an 'instanceof' can be any types when the right-hand side has a valid [Symbol.hasInstance] method.Β #63219

@xuld

Description

@xuld

πŸ”Ž Search Terms

in:title instanceof

πŸ•— Version & Regression Information

⏯ Playground Link

https://www.typescriptlang.org/play/?#code/IwAglgdgzgLghhAxgUwPYDMQG8QG0DKAngLYBGqANgHQAWcUAktPEsgLoAUAlNiAE7IYAVz4QQMPkOQgAvjICwAKAD0ykAD0QAFRrSKydDAC0dCABMQUMGekYQCEAHJIsBCgyOQyAB4AHAVBWqGLEQrAgpLaYMIS+0o4IhI4ANPZiqKQAVsiIMOKxtnz2+XEgvnB8cMSCyHxUHABMAMwArAAcXEA

πŸ’» Code

1 instanceof { [Symbol.hasInstance]() { return true }}

πŸ™ Actual behavior

Error: The left-hand side of an 'instanceof' expression must be of type 'any', an object type or a type parameter.(2358)

πŸ™‚ Expected behavior

No errors

Additional information about the issue

For custom 'Symbol.hasInstance' methods, number instanceof obj can return true or false according to implementation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions