-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Closed
Labels
In DiscussionNot yet reached consensusNot yet reached consensusSuggestionAn idea for TypeScriptAn idea for TypeScript
Description
TypeScript Version: 3.9.4
As specified here, https://tc39.es/ecma262/#sec-instanceofoperator, it should be sufficient for an object to define a function for the Symbol.hasInstance well-known symbol in order to be used as the right-hand side of the instanceof operator.
It seems like this was intended to be implemented based on these comments: #12728 (comment)
but for whatever reason that didn't happen it in the PR
Search Terms: Symbol.hasInstance
Code
({}) instanceof {[Symbol.hasInstance]: () => true}
// Running this in the browser evaluates to `true`Expected behavior:
No type-errors
Actual behavior:
({}) instanceof {[Symbol.hasInstance]: () => true}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2359: The right-hand side of an 'instanceof' expression must be of type 'any' or of a type assignable to the 'Function' interface type.Playground Link: Playground Link
Related Issues:
KilianKilmister, ExE-Boss, jacobmadsen, Josh-Cena, rotu and 2 more
Metadata
Metadata
Assignees
Labels
In DiscussionNot yet reached consensusNot yet reached consensusSuggestionAn idea for TypeScriptAn idea for TypeScript