-
Notifications
You must be signed in to change notification settings - Fork 13k
Labels
Domain: lib.d.tsThe issue relates to the different libraries shipped with TypeScriptThe issue relates to the different libraries shipped with TypeScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issueIn DiscussionNot yet reached consensusNot yet reached consensusSuggestionAn idea for TypeScriptAn idea for TypeScript
Description
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.
SlurpTheo, Draeken, indutny, anurbol, meldridon and 202 more
Metadata
Metadata
Assignees
Labels
Domain: lib.d.tsThe issue relates to the different libraries shipped with TypeScriptThe issue relates to the different libraries shipped with TypeScriptFix AvailableA PR has been opened for this issueA PR has been opened for this issueIn DiscussionNot yet reached consensusNot yet reached consensusSuggestionAn idea for TypeScriptAn idea for TypeScript