If that was to me, you need to read it in context.
tsc doesn't generate type checking logic, it does static tranpilation analysis based on what you've told it about the types. If you tell it the Web API result returns a number, it'll roll with it and find no issues (assuming you treat it like a number). Since it transpiles down to JavaScript, the variable will still get assigned a string and you get the same sort of an issue down the road. That's why it's important to get your type definitions correct as well as potentially validate them at the boundaries with a typeof check.
Also bear in mind union types and nullability are supported in TypeScript and should be considered and used. The benefits once you understand them are great, however.
If that was to me, you need to read it in context.
tsc
doesn't generate type checking logic, it does static tranpilation analysis based on what you've told it about the types. If you tell it the Web API result returns anumber
, it'll roll with it and find no issues (assuming you treat it like anumber
). Since it transpiles down to JavaScript, the variable will still get assigned astring
and you get the same sort of an issue down the road. That's why it's important to get your type definitions correct as well as potentially validate them at the boundaries with atypeof
check.Also bear in mind union types and nullability are supported in TypeScript and should be considered and used. The benefits once you understand them are great, however.
Matt - my response saying the answer given was incorrect was not directed at you. I've edited it to make that clearer ;)