Among these is TypeScript, the brainchild of Anders Hejlsberg. The creator of Turbo Pascal and C# has created on behalf of Microsoft an important project that delivers useful benefits now and is moving forward nicely.
Getting started with TypeScript is easy
Visual Studio is one consumer of those services. Others include WebStorm, Eclipse, and Sublime Text. There’s also the TypeScript playground, an interactive webpage that completes statements, prompts for parameters and their types, and warns about type errors.
How to get started with TypeScript
“Instead of having a switch that turns types on and off,” says Hejlsberg, “we have a dial.” You can invest incremental effort for incremental reward. As you add annotations, you improve your own ability to reason about the code, and you enable tools to provide more powerful automated support for that reasoning.
There’s also a multiplier effect because the TypeScript compiler works hard to infer types where it can. If you tell it that a function returns a string, it will know that a variable holding the result of that function is a string, even if you haven’t annotated the variable with the string type. If you later try to assign it a number, the compiler will complain.
TypeScript has a (software) test for that
We can debate the feasibility of writing tests that obviate the need for static typing. But if you buy the argument that type safety becomes important at large scale, TypeScript invites you to consider how you want to invest your testing effort.
Tests are, after all, another kind of overhead: more code to write and maintain. Arguably what can be tested mechanically, should be. If computers can figure out whether two software objects are compatible, people ought to delegate that job to them. Writing tests, like writing the software those tests exercise, is a creative act that should require and benefit from human intelligence. Automatic type checking is, from this point of view, a way to free up human creativity for higher purposes.
One of those higher purposes is effective naming. “There are only two hard things in computer science,” it’s famously said, “cache invalidation and naming things.” The names of variables, functions, classes, and modules are the most fundamental kind of documentation.
ECMAScript 6 took a major step forward. It provided a standard way to organize programs, which may spread across many files, as sets of modules. That mechanism, which TypeScript adopted, is a boon for large-scale development. When module dependencies are declared in a standard way, programmers can more readily understand those dependencies, tools can automate that understanding, and code refactoring becomes less risky.