@vue/eslint-config-typescript
ESLint configuration for Vue 3 + TypeScript projects.
See @typescript-eslint/eslint-plugin for available rules.
This config is specifically designed to be used by create-vue setups
and is not meant for outside use (it can be used but some adaptations
on the user side might be needed - for details see the config file).
A part of its design is that this config may implicitly depend on
other parts of create-vue setups, such as eslint-plugin-vue being
extended in the same resulting config.
[!NOTE]
The current version doesn't support the legacy .eslintrc* configuration format. For that you need to use version 13 or earlier. See the corresponding README for more usage instructions.
Installation
npm add --dev @vue/eslint-config-typescript
Please also make sure that you have typescript and eslint installed.
Usage
Because of the complexity of the configurations, this package exports several utilities:
defineConfigWithVueTs, a utility function whose type signature is the same as the config function from typescript-eslint, but will modify the given ESLint config to work with Vue.js + TypeScript.
vueTsConfigs, contains all the shared configurations from typescript-eslint (in camelCase, e.g. vueTsConfigs.recommendedTypeChecked), and applies to .vue files in addition to TypeScript files.
- a Vue-specific config factory:
configureVueProject({ scriptLangs, rootDir }). More info below.
Minimal Setup
import pluginVue from 'eslint-plugin-vue'
import {
defineConfigWithVueTs,
vueTsConfigs,
} from '@vue/eslint-config-typescript'
export default defineConfigWithVueTs(
pluginVue.configs['flat/essential'],
vueTsConfigs.recommended,
)
The above configuration enables the essential rules for Vue 3 and the recommended rules for TypeScript.
All the <script> blocks in .vue files MUST be written in TypeScript (should be either <script setup lang="ts"> or <script lang="ts">).
Advanced Setup
import pluginVue from 'eslint-plugin-vue'
import {
defineConfigWithVueTs,
vueTsConfigs,
configureVueProject,
} from '@vue/eslint-config-typescript'
configureVueProject({
tsSyntaxInTemplates: true,
scriptLangs: [
'ts',
'js',
'tsx',
'jsx',
],
allowComponentTypeUnsafety: true,
rootDir: import.meta.dirname,
})
export default defineConfigWithVueTs(
pluginVue.configs["flat/essential"],
vueTsConfigs.base,
)
Linting with Type Information
Some typescript-eslint rules utilizes type information to provide deeper insights into your code.
But type-checking is a much slower process than linting with only syntax information.
It is not always easy to set up the type-checking environment for ESLint without severe performance penalties.
So we don't recommend you to configure individual type-aware rules and the corresponding language options all by yourself.
Instead, you can start by extending from the recommendedTypeChecked configuration and then turn on/off the rules you need.
import pluginVue from 'eslint-plugin-vue'
import {
defineConfigWithVueTs,
vueTsConfigs,
} from '@vue/eslint-config-typescript'
export default defineConfigWithVueTs(
pluginVue.configs['flat/essential'],
vueTsConfigs.recommendedTypeChecked
)
Use As a Normal Shared ESLint Config (Not Recommended)
You can use this package as a normal ESLint config, without the defineConfigWithVueTs helper. But in this case, overriding the rules for .vue files would be more difficult and comes with many nuances. Please be cautious.
You can check the documentation for 14.1 and earlier versions for more information.
Further Reading