Skip to content

tsc

tsc is the official type checker that comes with TypeScript.

Installation

You have to install TypeScript first. Currently TypeScript v5 is supported.

shell
npm install typescript -D
shell
yarn add typescript -D
shell
pnpm install typescript -D
shell
bun install typescript -d

Configuration

tsconfig

You should use the tsconfig file provided with the project initialization whenever possible, or adjust on top of it.

If the tsconfig file was not provided with the project initialization, you can use tsconfig/bases, or adjust on top of it.

CLI

Update your package.json and add type-check script.

json
{
  "scripts": {
    "type-check": "tsc -p tsconfig.json --noEmit"
  }
}

For Vue projects, you need to change tsc to vue-tsc.

json
{
  "scripts": {
    "type-check": "vue-tsc -p tsconfig.json --noEmit"
  }
}

Specify tsconfig files explicitly

Some projects may provide more than one tsconfig file for initialization, for example, create-vue provides 4 tsconfig.json files. If you don't explicitly specify the tsconfig file, tsc / vue-tsc will default to tsconfig.json, which may not work as you expect. If possible, specify the tsconfig file explicitly.

Integration

VSC

VSC comes with a TypeScript plugin. VSC comes with a TypeScript plugin. For Vue projects, please follow the Official website to configure the settings accordingly.

WebStorm

WebStorm comes with a TypeScript plugin.

lint-staged

tsc / vue-tsc needs to go through all the project files in order to be able to analyze them, which also means that it's not really possible to only run tsc / vue-tsc on a staging file. See lint-staged#1223 and lint-staged#1352 for more information.

As an alternative, you should run tsc / vue-tsc before releasing a new version or in CI.

Released under the MIT License.