-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed
Labels
Fix AvailableA PR has been opened for this issueA PR has been opened for this issue
Milestone
Description
π Search Terms
hasinstance, instanceof, 2359, TS2359
π Version & Regression Information
- I was unable to test this on prior versions because this is recent functionality introduced in Support custom 'Symbol.hasInstance' methods when narrowing 'instanceof'Β #55052
β― Playground Link
π» Code
type HasInstanceOf = {
[Symbol.hasInstance](x:unknown): boolean
}
// ok
function myInstanceOf(x:unknown, c:HasInstanceOf){
return x instanceof c
}
// broken
function myInstanceOfIntersection(x:unknown, c:HasInstanceOf & object){
return x instanceof c
}
// broken
function myInstanceOfGeneric<C extends HasInstanceOf>(x:unknown, c:C){
return x instanceof c
}
π Actual behavior
The second and third examples give error TS2359
The right-hand side of an 'instanceof' expression must be either of type 'any', a class, function, or other type assignable to the 'Function' interface type, or an object type with a 'Symbol.hasInstance' method.
In all cases, the right-hand side is an object type with a Symbol.hasInstance
method.
π Expected behavior
I expect all three examples to typecheck.
Additional information about the issue
No response
Metadata
Metadata
Assignees
Labels
Fix AvailableA PR has been opened for this issueA PR has been opened for this issue