Skip to content

Array not assignable to ReadonlyArray with subclass items #10368

Closed
@stephanedr

Description

@stephanedr

TypeScript Version: 2.0.0

Code

class A {
    a: string;
}
class B extends A {
    b: string;
}
function f(a: ReadonlyArray<A>): void { }
f([new A()]);           // OK
f([new A(), new B()]);  // OK
f([new B()]);           // Error

Expected behavior:
To compile.

Actual behavior:
error TS2345: Argument of type 'B[]' is not assignable to parameter of type 'ReadonlyArray'.
Types of property 'concat' are incompatible.
Type '(...items: (B | B[])[]) => B[]' is not assignable to type '{ <U extends ReadonlyArray>(...items: U[]): A[]; (...items: A[]): A[]; }'.
Types of parameters 'items' and 'items' are incompatible.
Type 'A' is not assignable to type 'B | B[]'.
Type 'A' is not assignable to type 'B[]'.
Property 'length' is missing in type 'A'.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptDomain: lib.d.tsThe issue relates to the different libraries shipped with TypeScriptFixedA PR has been merged for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions