- Touring the Template Application
- Building Your Own Types
- Creating Multiple Types and Interfaces
- Interfaces and Structural Typing
- Why Should You Use TypeScript?
Why Should You Use TypeScript?
Language innovation is about developer productivity. We start using newer languages because we’re more productive than when using our previous tools. That’s how I feel about TypeScript: I’m more productive in TypeScript than I am in JavaScript. I believe you and your team will be more productive as well.
But using TypeScript doesn’t mean that you can avoid learning some JavaScript. TypeScript and JavaScript are very complementary. TypeScript’s idioms are consistent with JavaScript’s idioms. You can’t view TypeScript as “C# in a browser.” You’ll be much more productive if you think of TypeScript as a new, more productive vocabulary for large JavaScript development.
In this article, I demonstrated many of the features that make TypeScript a more productive language than JavaScript. You can create types by using a natural vocabulary. Those types can include overloads of different methods, such as with specialized signatures. But the type system isn’t like C#, Java, or C++; it’s a structural type system. Code doesn’t need to declare the types of interfaces supported, return values, or all local variables. The TypeScript compiler can infer that support from the usage and the definition of types. TypeScript also supports generics in a manner consistent with that of current JavaScript libraries. And, of course, my favorite feature: marshalling this on lambda-style methods.
Finally, TypeScript interacts well with JavaScript. You can avoid marshalling this by declaring methods using the classic JavaScript function syntax. You can also declare variables using the any type when JavaScript methods may return unrelated types, depending on the inputs.
TypeScript is a step forward for JavaScript-based web development, making your code more productive and easier to maintain.