- Typescript is a programming language, it is a superset of Javascript that provides optional static typing for your code.
- It is an open source object oriented programming language by Microsoft.
- It has been public since 2012!
- Check out the codebase here.
It offers interfaces and types for data as you define it.
Typescript shows errors at compile time so you will rarely have any errors at runtime.
Javascript code you often view your errors first at runtime.
This makes your programming process clean and simple.
Run tsc -- init
to create a tsconfig.json
file and specify compiler options
Run tsc -p tsconfig.json
to use the config file when compiling.
Typescript code is easier to scale. At a design level, you’ll need to have designed types & interfaces early on.
When using firebase/Mongo where your schemas are fluid, you can use TS to enforce types to your DB on the codebase level.
When joining a new team, you can understand the codebase relationships and scope better when it’s in TS.
npm install typescript -g
npm install @types/node -g
Run tsc -- init
to create a tsconfig.json
file and specify compiler options
Run tsc -p tsconfig.json
to use the config file when compiling.
Cannot redeclare block-scoped variable <>
- This is actually a feature in TS which is about transpiled Typescript code. A similar .js file is created which means your objects are now available twice. This results in this error in your ts files.
How to solve for it
- Modularise by adding export {}
- Create a config file with your compiler options