What is TypeScript?

TypeScript is a free, open-source programming language developed and maintained by Microsoft. It is 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 many advantages:

  • The language is easy to learn, because it is in fact ECMAScript 6. In addition, you annotate the code with typing information. The TypeScript type system is a very flexible one that does not 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 multiple source code files that adhere to the ECMAScript 6 module standard.

  • Because you cannot run TypeScript code as-is in a web browser, it must be compiled/transpiled to JavaScript. The TypeScript compiler does this for you, and takes a number of additional actions:

    • 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 your code is organized 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 is still possible to write faulty code that the compiler will approve.

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. Fortunately, it is possible to integrate TypeScript with existing JavaScript code, and you do not even have to give up type safety to do so. TypeScript allows you to 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 simply 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.

TypeScript in LuciadRIA

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