Skip to content

TS 2.4.1: ReadonlyArray<Identifiable> not assignable to type ReadonlyArray<T> even though <T extends Identifiable> #16805

@mmc41

Description

@mmc41

TypeScript Version: 2.4.1

Code

export interface Identifiable {
 id: string;
}

export function test<T extends Identifiable>(): ReadonlyArray<T> {
    const result: ReadonlyArray<Identifiable> = [];
    return result;
}

Expected behavior:
Should compile ok.

Actual behavior:

Error: 'Type 'ReadonlyArray<Identifiable>' is not assignable to type 'ReadonlyArray<T>'.
  Type 'Identifiable' is not assignable to type 'T'.
```'

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions