Open
Description
openedon Jul 7, 2017
TypeScript Version: 2.4.1
Code
declare interface T {
foo: string;
}
const immutable: T | ReadonlyArray<T> = [];
if (Array.isArray(immutable)) {
const x = immutable; // Any[] - Should be ReadonlyArray<T>
}
const mutable: T | Array<T> = [];
if (Array.isArray(mutable)) {
const x = mutable; // T[]
}
Expected behavior: Should type narrow to ReadonlyArray<T>
, or at the very least T[]
.
Actual behavior: Narrows to any[]
. Doesn't trigger warnings in noImplicitAny mode either.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment