TypeScript Version: 2.3.1
Code
import*as_from'lodash'vartestObject={'a': [{'b': {'c': 'boo'}}]};if(_.get(testObject,'a[0].b.c','foo')==='boo'){//Error: TS2365leta="boo"==="foo"//Error: TS2365letb=("boo"asstring)==="foo"letc="foo"==="foo"console.log(`My results are a=${a}, b=${b} and c=${c}`)}Expected behavior:
No type related errors, and the resulting code outputs
> My values are a=false, b=false and c=true
Note: I would be fine if tsc produced errors (or better yet warned) about the no-op lines (all the lets) and let me know I was doing work for no reason. It does not do this
Actual behavior:
I get two errors both on the line listed above with the comment //Error: TS2365. The errors are
test.ts(4,5): error TS2365: Operator '===' cannot be applied to types '"foo"' and '"boo"'. test.ts(5,11): error TS2365: Operator '===' cannot be applied to types '"boo"' and '"foo"'.
I have three questions
- Why is the errors about types, when both sides are strings?
- Why does
"foo" === "foo" work fine, but not "boo" === "foo"? - Why does casting to
string fix it?
and a bonus, why is lodash getting sucked into this. (note, the lodash is my actual production issue, the rest was just trying to explore the problem)
TypeScript Version: 2.3.1
Code
Expected behavior:
No type related errors, and the resulting code outputs
> My values are a=false, b=false and c=trueNote: I would be fine if tsc produced errors (or better yet warned) about the no-op lines (all the
lets) and let me know I was doing work for no reason. It does not do thisActual behavior:
I get two errors both on the line listed above with the comment
//Error: TS2365. The errors areI have three questions
"foo" === "foo"work fine, but not"boo" === "foo"?stringfix it?and a bonus, why is
lodashgetting sucked into this. (note, the lodash is my actual production issue, the rest was just trying to explore the problem)