You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
A clear and concise description of what the bug is.
if (instanceof C) can be used for classes which has private constructors potentially, but P.instanceof can't. It's because type AnyConstructor = abstract new (...args: any[]) => any; cannot accept private constructors.
TypeScript playground with a minimal reproduction case
I tried to find the universal class of all classes including private constructors, but I coundn't get it. Maybe I'm hitting the limitation of TypeScript...
The text was updated successfully, but these errors were encountered:
By trying {} instanceof {}, I got the following message.
Theright-handsideofan '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.
So it seems we can just use Function | { readonly [Symbol.hasInstance]: any } instead to support any types which can be also used in instanceof right-hand operand.
Ah thanks for the report, that's too bad. I'm not sure I can fix it in ts-pattern because instanceOf requires it's parameter to be a subtype of abstract new (...any) => any in order to pass it to the native InstanceType helper. Without this contraint, I can't narrow the input type for this branch:
Describe the bug
A clear and concise description of what the bug is.
if (instanceof C)
can be used for classes which has private constructors potentially, butP.instanceof
can't. It's becausetype AnyConstructor = abstract new (...args: any[]) => any;
cannot accept private constructors.TypeScript playground with a minimal reproduction case
Playground
Versions
I tried to find the universal class of all classes including private constructors, but I coundn't get it. Maybe I'm hitting the limitation of TypeScript...
The text was updated successfully, but these errors were encountered: