is typescript truly strict?

I am new to typescript so this may be a dumb question or a odd question, which I don’t doubt that it is, but please look at this example of what I mean:


var num:number = 5

compiled to js:

"use strict";
var num = 5;

in the compiled code there is not anything really restricting num from being anything but a number. So, is typescript really strict? Or is it just creating the allusion of being strict? Or perhaps is there a option in the tsconfig.json that is suppose to make the code strict that I missed?

>Solution :

TypeScript tries to guarantee types at compile time, at runtime everything is dynamic. So if you communicate with an API and type it using TypeScript but the API delivers something else, then the "illusion", as you called it, will break.

Leave a Reply