Configure local typescript compiler inside package.json

Ok... It seems like it was as simple as this (see below). Answering it here, for anyone else looking for the answer. Or please let me know if there are better solutions.

Configure the script like "tsc": "tsc" inside package.json. Then just run npm run tsc and it will use your tsc version you have installed locally, and discover your tsconfig.json of course. It doesn't use your global version - as I uninstalled that one - just entering tsc in the command line errors out.

E.g.:

Check the repo* where I was playing with this.

package.json

{
  "name": "tscnodejsgettingstarted",
  "version": "1.0.0",
  "description": "",
  "main": "app/index.js",
  "scripts": {
    "start": "npm run tsc && node app/index.js",
    "tsc": "tsc"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "typescript": "2.1.6"
  }
}

*repo: https://github.com/pluralsight-courses/typescript-fundamentals/tree/master/001-GettingStarted


You can also use the prestart script. By default it runs before the start command (see all the default scripts that you can set up here).

  "scripts": {
    "prestart": "npm run tsc",
    "start": "node app/index.js",
    "tsc": "tsc"
  }