-
Notifications
You must be signed in to change notification settings - Fork 12.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
instanceof Object
does not work with the in
operator
#51007
Comments
You can just use |
@MartinJohns That is the workaround I used, forgot to mention it. I still think ideally it should work. |
I think |
The |
I don't see why not -- narrowing should generally be transitive (i.e. if |
Should we open a new issue for this problem, or does it belong here? export function isHTMLTable<T extends object | null>(table: T): boolean {
return !!table && 'html' in table; // error!
// Type 'NonNullable<T>' may represent a primitive value, which is not permitted as
// the right operand of the 'in' operator.(2638)
} |
@jcalz I'd say that this is a different problem as the issue here, at least from my PoV, was very related to export function isHTMLTable(table: object | null): boolean {
return !!table && 'html' in table;
} |
Bug Report
π Search Terms
instanceof Object
in
π Version & Regression Information
β― Playground Link
Playground Link
π» Code
π Actual behavior
Error: Type '{}' may represent a primitive value, which is not permitted as the right operand of the 'in' operator
π Expected behavior
Should type check
Notes
Seems to be introduced by #50666 which correctly introduces an error if
in
is used on non objects. The issue is that it does not handle testing for objects withinstanceof Object
The text was updated successfully, but these errors were encountered: