Skip to content

Constrained types is not assignable to constrainer union types, and failed to narrow its type #8563

Description

TypeScript Version:

master

Code

function f<T extends string[] | {}>(a: T) {
  if (a instanceof Array) {
    a = a;
  }
}

Expected behavior:

$ node built/local/tsc.js index.ts

Actual behavior:

$ node built/local/tsc.js index.ts
index.ts(3,5): error TS2322: Type 'any[]' is not assignable to type 'T'.

Metadata

Metadata

Assignees

No one assigned

    Labels

    SuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions