Trabla: TypeScript & JavaScript: compile ts to js
This tutorial explains how to compile TypeScript script (.ts) to JavaScript ( .js )
via npm (the node package manager) on windows.
Solving:
1. Install npm ( nodejs package manager ):
Howto: http://codingtrabla.blogspot.com/2016/03/npm-npm-install-on-windows.html
2. Sample file demo.ts
class Greeter {
greeting: string;
constructor(message: string) {
this.greeting = message;
}
greet() {
return "Hello, " + this.greeting;
}
}
var greeter = new Greeter("world");
3. Run windows command line, change directory to demo.ts location and execute following commands
npm install -g typescript
tsc demo.ts
Where npm install -g typescript - install typescript component for node,js globally
tsc demo.ts - compile ts to js.
C:\Users\samuraikit>cd C:\Users\samuraikit\Desktop\typescript-demo
C:\Users\samuraikit\Desktop\typescript-demo>npm install -g typescript
C:\Users\samuraikit\AppData\Roaming\npm\tsserver -> C:\Users\samuraikit\AppData\
Roaming\npm\node_modules\typescript\bin\tsserver
C:\Users\samuraikit\AppData\Roaming\npm\tsc -> C:\Users\samuraikit\AppData\Roami
ng\npm\node_modules\typescript\bin\tsc
C:\Users\samuraikit\AppData\Roaming\npm
`-- typescript@1.8.7
C:\Users\samuraikit\Desktop\typescript-demo>tsc demo.ts
C:\Users\samuraikit\Desktop\typescript-demo>
4. Result - demo.js file
No comments:
Post a Comment