What’s TypeScript?

TypeScript is a free, open-source programming language developed and maintained by Microsoft. It’s a strict superset of JavaScript, and adds optional static typing and class-based object-oriented programming to the language. TypeScript is gaining more and more popularity as a better language to develop large web applications because of its advantages:

  • The language is easy to learn, because it’s in fact ECMAScript 6. You also annotate the code with typing information. The TypeScript type system is a flexible one that doesn’t renounce its heritage: you can write TypeScript that still looks like idiomatic JavaScript, but with type information in your code.

  • TypeScript also supports modular software development. You can organize your TypeScript code in several source code files that adhere to the ECMAScript 6 module standard.

  • Because you can’t run TypeScript code as-is in a web browser, you must compiled/transpile it to JavaScript. The TypeScript compiler does this for you, and takes these actions too:

    • It statically verifies the correctness of your code, based on the typing information you provided.

    • It transforms the TypeScript code to executable JavaScript code.

    • If you organized your code into modules, it can transform your modules to popular standards like AMD, CommonJS, and the ES6 module format

  • For software engineers, a major advantage is the development tool support. With TypeScript typing, IDEs like Visual Studio code and WebStorm offer support for code completion, static checking, and re-factoring during the development of JavaScript applications.

The typing approach of TypeScript also has disadvantages. One major source of discussion is the soundness of the TypeScript typing system, because it’s still possible to write faulty code that the compiler approves.

Writing your own application in TypeScript is one thing, but when you are building a large web application, you often depend on a lot of third-party JavaScript libraries. Those libraries may not have been written in TypeScript, but in plain JavaScript. Luckily, it’s possible to integrate TypeScript with existing JavaScript code, and you don’t even have to give up type safety to do so. With TypeScript , you can write type declaration files, which describe the TypeScript API of existing JavaScript libraries. What’s even better is that most of the time you don’t need to write those type declaration files yourself. Instead, you download an existing declaration from the internet repositories used by a vast community of TypeScript developers to share their work. One of those repositories is the DefinitelyTyped GitHub repository, where you can find thousands of TypeScript type declaration files for popular JavaScript libraries.

Using TypeScript in LuciadRIA

For more information about TypeScript, and how it is used as of LuciadRIA 2020, see: