The merits of typed vs. untyped languages have been debated for decades. Arguments for static types include:
Because TypeScript's output is independent of its types, TypeScript has no impact on performance. The argument for using TypeScript rests on the other three advantages.
Arguments against type systems include:
TypeScript offers some ways to address all of these issues:
any
type. The same is true for external modules.The arguments for and against type systems in general apply equally well to TypeScript. Using TypeScript increases the overhead to starting a new project. But over time, as the project increases in size and gains more contributors, the hope is that the pros of using it (safety, readability, tooling) become stronger and outweigh the cons. This is reflected in TypeScript's motto: "JavaScript that scales."
TypeScript catches type errors early through static analysis:
function double(x: number): number {
return 2 * x;
}
double('2');
// ~~~ Argument of type '"2"' is not assignable to parameter of type 'number'.