TypeScript Basics


Typescript

Typescript is a super-set of JavaScript which provides type definitions. It is a strongly typed programming language.

Starting a Typescript Project

  1. To start a TypeScript Project, first of all, install TypeScript and ts-node as a dev-dependency
yarn add typescript ts-node -D
  1. Create a tsconfig.json file at the root of your project and add the following configurations (Enough Config to get started).
{
"compilerOptions": {
"outDir": "./dist",
"lib": ["ESNext"],
"esModuleInterop": true
}
}
PropertyFunction
outDirWhere your compiled JavaScript will be stored
libInclude API's from specified versions.
esModuleInteropWith flag esModuleInterop we can import CommonJS modules in compliance with es6 modules spec.
  1. Inside package.json, add the following scripts
"scripts": {
"build": "tsc",
"dev": "ts-node app.ts"
}
  1. Run yarn dev to run your app.