Reputation: 2036
I'm looking to move a vanilla node.js project to TypeScript and I'm curious about how to restart my server with the latest changes without needing to run tsc from the command line each time I make a change.
I see from this answer two options: ts-node
and tsc --watch
Can someone provide a little color on the difference between these two options? I understand they accomplish the same goal, but how are they different and in which situation should I use one over the other?
Upvotes: 7
Views: 14894
Reputation: 21
Just type this in the terminal (In my case it's VS Code with Live Server Installed) --> tsc (Your Typescript File Name).ts --watch
Upvotes: 0
Reputation: 3845
tsc --watch
(or tsc -w
; same thing).
When your run that command, it will compile .ts files to .js when the .ts files are changed (via saving).
Upvotes: 5
Reputation: 184
You can add this script
"name_for_your_script" : "tsc <ts file name> --outFile <js file name> -w",
to your package.json file in scripts part and type this code
npm run name_for_your_script
into your terminal. this will automatically compile your ts codes when you save it
Upvotes: 6