- Home
- Typescript
Introduction to TypeScript
TypeScript is a programming language that enhances JavaScript by adding static types. It was created by Microsoft to help developers write more reliable and maintainable code, especially in large-scale applications. With TypeScript, you can catch potential errors early in the development process, making your code safer and easier to manage.
At its core, TypeScript is still JavaScript. The TypeScript syntax is very similar to JavaScript, with the addition of type annotations that help ensure your code behaves as expected. TypeScript files use the .ts
extension, which distinguishes them from standard JavaScript files.
The typical workflow with TypeScript involves three main steps:
-
Writing TypeScript Code: You write your code in
.ts
files, using TypeScript's enhanced syntax, which includes static types, interfaces, and more. -
Transpiling: The TypeScript compiler (TSC) checks your code for errors and converts it into JavaScript. This transpiled JavaScript can then be executed in any environment that supports JavaScript, like browsers or Node.js.
-
Executing JavaScript: The output of the transpilation process is plain JavaScript, which is compatible with all JavaScript engines.
For example, consider the following TypeScript code:
let name: string = 'Anna';
After transpilation, the code will be converted to JavaScript:
let name = 'Anna';
As you can see, the TypeScript code is very similar to JavaScript, but with the added benefit of type annotations.