DEV Community

Discussion on: Practical Ways to Write Better JavaScript

Collapse
 
juancarlospaco profile image
Juan Carlos

TS types are really bad, you should need to do stuff like:

let foo: number = 42
if (foo > 100) {
  throw_error_too_big();
};
if (foo < 0) {
  throw_error_too_small();
};
// Actually use foo

This Nim lang instead only takes integer from 0 to 100:

let foo: range[0..100] = 42

šŸ¤”

Collapse
 
taillogs profile image
Ryland G

Iā€™m sorry but this is a really weak argument for Typescript having a bad type system. This is already a feature that is planned for TS too.

Also your code is not optimal TS and could be condensed to a single line.