Skip to content

Instanceof left-hand-side check rejects generic index access types #19298

Description

Reported by Christian Yang (@yangchristian) in #2775 (comment)

I repro Andreas Larsen (@larsenwork)'s issue with the following:

typeCreatedOrUpdatedAt={createdAt: Date|string}|{updatedAt: Date|string};constdatePropComp=<TextendsCreatedOrUpdatedAt,KextendskeyofT>(a: T,b: T,field: K)=>{// The left-hand side of an 'instanceof' expression must be of type 'any', an object type or a type parameter.constdateA=a[field]instanceofDate ? a[field] : newDate(a[field]);constdateB=b[field]instanceofDate ? b[field] : newDate(b[field]);returndateA.getTime()-dateB.getTime();};datePropComp({updatedAt: Date()},{updatedAt: Date()},'updatedAt')

Playground link

Metadata

Metadata

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions