Skip to content

Array of generic functions not assignable to ReadonlyArray #20454

Closed
@ghost

Description

TypeScript Version: 2.7.0-dev.20171203

Code

type Fn<T> = <U extends T>(x: U) => U
function f<T, T1 extends T>(fns: Array<Fn<T>>, t1: T1) {
    const a: ReadonlyArray<Fn<T1>> = fns; // This is an error

    const b: ReadonlyArray<Fn<T>> = fns;
    const c: ReadonlyArray<Fn<T1>> = b; // But this works
}

Expected behavior:

No error.

Actual behavior:

src/a.ts(3,11): error TS2322: Type 'Fn<T>[]' is not assignable to type 'ReadonlyArray<Fn<T1>>'.
  Types of property 'includes' are incompatible.
    Type '(searchElement: Fn<T>, fromIndex?: number) => boolean' is not assignable to type '(searchElement: Fn<T1>, fromIndex?: number) => boolean'.
      Types of parameters 'searchElement' and 'searchElement' are incompatible.
        Types of parameters 'x' and 'x' are incompatible.
          Type 'U' is not assignable to type 'T1'.
            Type 'T' is not assignable to type 'T1'.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Design LimitationConstraints of the existing architecture prevent this from being fixed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions