-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Closed
Labels
Working as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug
Description
TypeScript Version: 2.7.0-dev.201xxxxx
Code
//This one, tsc give me an error.
const lab = 'icon-yes';
if (lab === '321') {} //<- [ts] Operator '===' cannot be applied to types '"icon-yes"' and '"321"'.
//All of below are correct.
const lb: string = 'icon-yes';
if (lb === '321') {}
let la = 'icon-yes'; //<- this one , I just replace `const` to `let`. Why it became correct?
if (la === '321') {}
const labc = 'icon-yes';
if (labc === 'icon-yes') {} //<- compare the error case. Do not understand.
let labcd = 'icon-yes';
if (labcd === '321') {}Expected behavior:
const lab = 'icon-yes'; I think the variable lab should be string type by type inference.
All of these cases should be correct.
Actual behavior:
Can not figure out why.
samao and fenying
Metadata
Metadata
Assignees
Labels
Working as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug