Skip to content

Rahul-Chauhan-2212/TypeScript-Learning

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 

Repository files navigation

TypeScript-Learning

This Repo is created for TypeScript Basic Learning

TypeScript is a super set of JavaScript

1)Installing typescript
a)Install node
b)Install Typescript

npm install -g typescript

2)Setting up Fundamentals Training Workspace
a)Create folder
b)create index.html with app.js as script
c)create app.ts
d)run below command to add dependencies in project

npm init

e)Then install lite server which is live server to reflet on the fly changes

npm install --save-dev lite-server

f)Run lite server in the root folder of index.html

npm start

g)running project after cloning

npm install

npm start

3)Core Types

  • number ---> 1,5.3,-10
  • string --->'Hi',"Hi",`Hi`
  • boolean --->true, false
  • object --->{age:30,name:'Rahul'}
  • Array --->[1,2,3]
  • Tuple --->[1,2]
  • fixed length and fixed type array
  • Enum ---->enum{NEW,OLD}
  • Any
  • Union --->number|string
  • Literal Types
  • Type Aliases
  • Function Types
  • Function Types and CallBacks
  • Unknown Type
  • Never Type

4)Watch Node
so that whenver a ts file is changes it automatically compiles

tsc app.ts --watch

tsc app.ts -w

Note:: Don't quit/CTRL+C, till you want this file to be in watch node

5)Compiling complete project

tsc --init

creates a tsconfig.json file

tsc --watch

compiles all project in watch mode

6)Excluding and including files while compilation Add Below lines in tsconfig.json

"exclude": ["node_modules"], "include": ["app.ts", "analytics.ts"]

7)Changing Compiler target
change target version in tsconfig.json

8)Source map
change source map property to true in tsconfig.json
this is used to debug the source and will generate .js.map file

9)RootDir and OutDir
outDir for js files
rootDir for ts files

10)noEmmitOnError=true don't create js file if ts file has errors

11)Enable all Strict Type Checking options
"strict": true
if want to disable some strict compilations then set that as false

12)There are some Quality Options too

  • "noUnusedLocals": true
  • "noUnusedParameters": true
  • "exactOptionalPropertyTypes": true
  • "noImplicitReturns": true
  • "noFallthroughCasesInSwitch": true
  • "noUncheckedIndexedAccess": true
  • "noImplicitOverride": true
  • "noPropertyAccessFromIndexSignature": true
  • "allowUnusedLabels": true
  • "allowUnreachableCode": true

13)Generics

14)Class

15)Interfaces