TypeScript is a free and open-source high-level programming language developed by Microsoft that adds static typing with optional type annotations to JavaScript. It is designed for the development of large applications and transpiles to JavaScript. TypeScript is a superset of JavaScript, meaning that all JavaScript programs are syntactically valid TypeScript, but they can fail to type-check for safety reasons. TypeScript may be used to develop JavaScript applications for both client-side and server-side execution (as with Node.js or Deno).
Some key features of TypeScript include:
-
Static Typing: TypeScript is a strongly typed programming language that builds on JavaScript, giving you better tooling at any scale. It adds syntax on top of JavaScript, allowing developers to add types. TypeScript allows specifying the types of data being passed around within the code, and has the ability to report errors when the types dont match.
-
Compatibility with JavaScript: TypeScript is a strict superset of ECMAScript 2015, which is itself a superset of ECMAScript 5, commonly referred to as JavaScript. As such, a JavaScript program is also a valid TypeScript program.
-
Object-Oriented Programming: Unlike JavaScript, which has yet failed to embrace object-oriented programming, TypeScript supports object-oriented programming concepts in the vein of classes, interfaces, and inheritance.
TypeScript originated from the shortcomings of JavaScript for the development of large-scale applications both at Microsoft and among their external customers. Challenges with dealing with complex JavaScript code led to demand for custom tooling to ease developing of components in the language. Syntactically, TypeScript is very similar to JScript .NET, another Microsoft implementation of the ECMA-262 language standard that added support for static typing and classical object-oriented language features such as classes, inheritance, interfaces, and namespaces.
To use TypeScript, a common way is to use the official TypeScript compiler, which transpiles TypeScript code into JavaScript. TypeScript files use the .ts extension rather than the .js extension of JavaScript files. TypeScript uses the JavaScript syntaxes and adds additional syntaxes for supporting Types. If you have a JavaScript program that doesn’t have any syntax errors, it is also a TypeScript program. This is very helpful if you’re migrating an existing JavaScript codebase to TypeScript.