DEV Community

Discussion on: Type checking JavaScript

Collapse
 
curtisfenner profile image
Curtis Fenner

What did you mean by TypeScript not being happy with checking for the existence of variables with !!? TypeScript is perfectly happy to do that:

const a: number | null = myFunction();
if (!!a) {
    const b: number = a; // typechecks
}
Enter fullscreen mode Exit fullscreen mode

I find myself far more productive in TypeScript because it lets me plan more (by writing types before the implementation, which often exposes silly things that I can fix before writing a lot of code) and generally be more hasty while still having confidence that my code is more or less correct. I use strict: true and rarely run into problems, especially because I can just use as in the uncommon cases that I can't convince the TypeScript compiler of something.