It took me a while to figure out the solution to this problem - it's in the original question. You need to have a script that calls tsc in your package.json file so that you can run:
npm run tsc
Include -- before you pass in options (or just include them in the script):
npm run tsc -- -v
Here's an example package.json:
{
"name": "foo",
"scripts": {
"tsc": "tsc"
},
"dependencies": {
"typescript": "^1.8.10"
}
}
Answer from ubershmekel on Stack OverflowIt took me a while to figure out the solution to this problem - it's in the original question. You need to have a script that calls tsc in your package.json file so that you can run:
npm run tsc
Include -- before you pass in options (or just include them in the script):
npm run tsc -- -v
Here's an example package.json:
{
"name": "foo",
"scripts": {
"tsc": "tsc"
},
"dependencies": {
"typescript": "^1.8.10"
}
}
Answer from ubershmekel on Stack OverflowIt took me a while to figure out the solution to this problem - it's in the original question. You need to have a script that calls tsc in your package.json file so that you can run:
npm run tsc
Include -- before you pass in options (or just include them in the script):
npm run tsc -- -v
Here's an example package.json:
{
"name": "foo",
"scripts": {
"tsc": "tsc"
},
"dependencies": {
"typescript": "^1.8.10"
}
}
As of npm 5.2.0 you no longer need an entry in the scripts section of package.json. You can now run the compiler with npx:
npx tsc
...and you don't have to update package.json with a new script every time you want to compile with different arguments.
This is not the tsc command you are looking for
Typescript: This is not the tsc command you are looking for
How to run tsc during npx
Is there a way to run TSC to do type-checking only for a single file?
Videos
I'm learning typescript and I'm trying to create a script that will execute js files created by tsc. This is my package.json:
{
"bin": "bin/tutorial.js",
"scripts": {
"start": "node bin/tutorial.js",
"prestart": "npm run build",
"build": "tsc"
}bin/tutorial.js is just a custom js file that I wrote that will execute the compiled js files in lib (tsconfig has outDir set to lib):
#!/usr/bin/env node
require('../lib/tutorial');I am able to run the script using npm start, since it will build beforehand. However if I clean the lib directory and do 'npx .' then the tsc build will never happen. This means that the lib directory will be empty and my bin/tutorial.js file won't be able to import the compiled js.
How do I ensure that my scripts executed with npx can run the build step beforehand?
» npm install tsx
» npm install typescript
» npm install ts-node