3 ms·
That's like saying the following is incorrect let foo: number; because at runtime you can assign a string to foo. Typescript's type system is for compile-
by petilon 3y ago
That's like saying the following is incorrect
let foo: number;
because at runtime you can assign a string to foo.
Typescript's type system is for compile-time checking, not runtime checking. The above definition is correct if at compile-time you want to check that all assignments to foo are of type number.
- tshaddox 3y agoThe difference is that TypeScript won’t let you assign a string to foo at runtime, but TypeScript will absolutely let you pass an object with additional properties at runtime.