Skip to content

Type parameters constrained to type alias of generic class can't be used with instanceof - TypeScript 4.8 regressionΒ #49937

@dragomirtitian

Description

@dragomirtitian

Bug Report

πŸ”Ž Search Terms

generic type parameters type aliases generic classes instanceof

πŸ•— Version & Regression Information

  • This changed between versions 4.7.3 and 4.8-beta

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

// If Table is non generic error does not occur
declare class TableClass<S = any>  {
    _field: S
}

export type Table = TableClass;

function fn<T extends Table>(o: T) {
    return o instanceof TableClass // error in 4.8
}

declare const o: Table;
o instanceof TableClass // This is ok 

πŸ™ Actual behavior

o instanceof TableClass causes an error when o is typed as a generic type parameter constrained to Table but not when o is typed as Table. This behavior is different in 4.7 and 4.8. In 4.7 neither of these was an error.

πŸ™‚ Expected behavior

o instanceof TableClass is valid in both cases

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issueHas ReproThis issue has compiler-backed repros: https://aka.ms/ts-repros

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions