Skip to content

instanceof Object does not work with the in operatorΒ #51007

Closed
@dragomirtitian

Description

@dragomirtitian

Bug Report

πŸ”Ž Search Terms

instanceof Object in

πŸ•— Version & Regression Information

  • This changed between versions 4.9.0-dev.20220919 and 4.9.0-dev.20220920

⏯ Playground Link

Playground Link

πŸ’» Code

export function isHTMLTable(table: unknown): boolean {
    return !!table && table instanceof Object && 'html' in table;
}

πŸ™ 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 with instanceof Object

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions