TYPE SCRIPT
-----------
http://osol-tutorials.blogspot.com/2020/12/typescript.html
https://www.youtube.com/watch?v=2pZmKW9-I_k&list=PL4cUxeGkcC9gUgr39Q_yD6v-bSyMwKPUI
https://www.youtube.com/watch?v=2pZmKW9-I_k
https://github.com/iamshaunjp/typescript-tutorial
npm install -g typescript
C:\Users\user\AppData\Roaming\npm\tsserver -> C:\Users\user\AppData\Roaming\npm\node_modules\typescript\bin\tsserver
C:\Users\user\AppData\Roaming\npm\tsc -> C:\Users\user\AppData\Roaming\npm\node_modules\typescript\bin\tsc
+ typescript@4.1.2
added 1 package from 1 contributor in 34.334s
Compile .ts to js
tsc tsFileName.ts jsFileName.js
if .ts file is to be compiled to js file of same name , no need to explicitly state js file name
WATCH PARAMAETER
tsc tsFileName.ts -w
tsc will watch for saving changes in tsFileName.js and automatically compile to js
explicit types
eg:
let strTyoeVar:string;
array
let strArrayVar:string[];
Object
let objVar:object;
Specific Type
let specificTypeObjVar:{
name:streing,
age:number
}
union types (mixed)
let mixedVar:(string|number);
let mixedArrayVar:(string|number)[] = [] ;
DYNAMIC TYPE
let dynamicTypeVar:any;
let dynamicTypeArrayVar:any[];
let dynamicTypeObjVar:{name:any,age:any};
Differentiating source TS and JS in seperate files
save .js in src/ts folder and js in public/js folder
first call
tsc --init
will create tscconfig.json
then edit
tscconfig.json
outDir:"./public/js",
rootDir:"./src/ts",
refer https://www.typescriptlang.org/docs/handbook/tsconfig-json.html
so that
in src/ts folder will compile js to public/js folder
by simply calling
tsc
No comments:
Post a Comment