Closed
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.