TypeScript is a programming language developed and maintained by Microsoft. The correct answer to the quiz question - TypeScript is a superset of which language? - is JavaScript. So, what does it mean for TypeScript being a superset of JavaScript? This simply means that every valid JavaScript program is also a valid TypeScript program.
TypeScript, in essence, extends JavaScript by adding types and some other features. The primary goal of TypeScript is to help catch mistakes early during the development process, rather than runtime, through a type system. For those familiar with statically typed languages such as C++, Java, or C#, TypeScript brings that same capability to JavaScript, making it a great choice for large-scale projects.
// JavaScript
let user = "Jane User";
// TypeScript
let user: string = "Jane User";
As shown above, TypeScript introduced a way of explicitly specifying types of values, leading to better tooling and documentation.
However, before a TypeScript file (.ts
) can run in a JavaScript environment, it must be transcompiled into JavaScript using the TypeScript compiler (tsc
). After running the TypeScript compiler, your TypeScript code (.ts
files) is converted to JavaScript (.js
files), which can then be interpreted by any JavaScript runtime (like a browser or Node.js).
One of the key benefits of using TypeScript over JavaScript is better tooling support with IntelliSense. TypeScript tooling can provide autocompletion, hinting and static checking capabilities that could help developers become more efficient and deliver more robust codebases.
It's important to remember that TypeScript isn't a replacement for JavaScript. Rather, it’s a tool that helps improve the quality of your JavaScript code and facilitate better development and collaboration within a larger team. Over time and with rising complexity of frontend Applications, TypeScript has become increasingly popular among JS developers for its benefits in development-time type safety and its capabilities to use advanced JavaScript features while providing a fallback for older browsers.
In the context of web development, a firm understanding of the underlying language JavaScript is absolutely recommended before jumping into TypeScript, because ultimately the browser understands JavaScript, not TypeScript. However, if you're comfortable with JavaScript, and especially if you're planning to write a large scale application or library, TypeScript is an excellent choice to make your codebase more resilient and maintainable.