vuejs / tsconfig

Base tsconfig for Vue 3 projects.
MIT License
302 stars 25 forks source link

@vue/tsconfig

TSConfigs for Vue projects to extend.

Requires TypeScript >= 5.0. For TypeScript v4.5 to v4.9, please use v0.1.x.

See below for the changes in v0.3.x.

Installation

npm add -D @vue/tsconfig

Usage

Add one of the available configurations to your tsconfig.json:

The Base Configuration (Runtime-agnostic)

"extends": "@vue/tsconfig/tsconfig.json"

Configuration for Browser Environment

"extends": "@vue/tsconfig/tsconfig.dom.json"

Configuration for Node Environments

First install the base tsconfig and types for the Node.js version you are targeting, for example:

npm add -D @tsconfig/node18 @types/node@18

If you are not using any bundlers, the Node.js code doesn't rely on any Vue/Vite-specific features, then these would be enough, you may not need to extend the Vue TSConfig:

"extends": "@tsconfig/node18/tsconfig.json",
"compilerOptions": {
  "types": ["node"]
}

Otherwise, if you are trying to use Vue components in Node.js environments (e.g. Server Side Rendering, Vitest, etc.), you will need to extend the Vue TSConfig along with the Node.js TSConfig:

"extends": [
  "@tsconfig/node18/tsconfig.json",
  "@vue/tsconfig/tsconfig.json"
],
"compilerOptions": {
  "types": ["node"]
}

Make sure to place @vue/tsconfig/tsconfig.json after @tsconfig/node18/tsconfig.json so that it takes precedence.

Emitting Declaration Files

As most Vue projects are built with bundlers, the default Vue TSConfig does not emit declaration files. If you are building a library or a component library, you can enable declaration file emitting by also extending @vue/tsconfig/tsconfig.lib.json in your tsconfig.json:

"extends": [
  "@vue/tsconfig/tsconfig.dom.json",
  "@vue/tsconfig/tsconfig.lib.json"
]

Migrating from TypeScript < 5.0

Some configurations have been updated, which might affect your projects: