镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
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'.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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