**TypeScript Version:** 3.1.6 **Code** ```ts const a1:[number, number, boolean] = [1, 0, false]; //... code if (a1[2]) { a1[2] = false; //error TS2322 } ``` **Expected behavior:** no error (run in TypeScript 2.9.2) **Actual behavior:** TS2322: Type 'false' is not assignable to type 'true'. why is the type cast to true ?
Activity
AlCalzone commentedon Nov 28, 2018
if (a1[2])checks for truthiness and thus narrows the type ofa[2]frombooleantotrue.ajafff commentedon Nov 28, 2018
first of all, this has nothing to do with type casting. this is an issue with narrowing.
This is fixed by #27574 which is part of v3.2.0-rc (and probably this week in v3.2.1)
typescript-bot commentedon Dec 12, 2018
This issue has been marked as a duplicate and has seen no activity in the last day. It has been closed automatic house-keeping purposes.