8000 docs: improve no-undef FAQ (#3082) · SanderHeling/typescript-eslint@1cf9243 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1cf9243

Browse files
authored
docs: improve no-undef FAQ (typescript-eslint#3082)
1 parent 0c0ca4a commit 1cf9243

File tree

1 file changed

+15
-2
lines changed
  • docs/getting-started/linting

1 file changed

+15
-2
lines changed

docs/getting-started/linting/FAQ.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,11 +187,24 @@ Instead, our tooling exists to **_augment_** TypeScript's built in checks with l
187187

188188
The `no-undef` lint rule does not use TypeScript to determine the global variables that exist - instead, it relies upon ESLint's configuration.
189189

190-
You can [manually define the set of allowed `globals` in your ESLint config](https://eslint.org/docs/user-guide/configuring/language-options#specifying-globals), and/or you can use one of the [pre-defined environment (`env`) configurations](https://eslint.org/docs/user-guide/configuring/language-options#specifying-environments).
190+
We strongly recommend that you do not use the `no-undef` lint rule on TypeScript projects. The checks it provides are already provided by TypeScript without the need for configuration - TypeScript just does this significantly better.
191191

192192
As of our v4.0.0 release, this also applies to types. If you use global types from a 3rd party package (i.e. anything from an `@types` package), then you will have to configure ESLint appropriately to define these global types. For example; the `JSX` namespace from `@types/react` is a global 3rd party type that you must define in your ESLint config.
193193

194-
We strongly recommend that you do not use the `no-undef` lint rule on TypeScript projects. The checks it provides are already provided by TypeScript without the need for configuration - TypeScript just does this significantly better.
194+
Note, that for a mixed project including JavaScript and TypeScript, the `no-undef` rule (like any role) can be turned off for TypeScript files alone by adding an `overrides` section to .eslintrc.json:
195+
196+
```json
197+
"overrides": [
198+
{
199+
"files": ["*.ts"],
200+
"rules": {
201+
"no-undef": "off"
202+
}
203+
}
204+
]
205+
```
206+
207+
If you choose to leave on the ESLint `no-undef` lint rule, you can [manually define the set of allowed `globals` in your ESLint config](https://eslint.org/docs/user-guide/configuring/language-options#specifying-globals), and/or you can use one of the [pre-defined environment (`env`) configurations](https://eslint.org/docs/user-guide/configuring/language-options#specifying-environments).
195208

196209
<br />
197210
<br />

0 commit comments

Comments
 (0)
0