@typescript-eslint/eslint-plugin 8.33.1-alpha.5 → 8.33.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +9 -10
- package/docs/rules/README.md +0 -57
- package/docs/rules/TEMPLATE.md +0 -36
- package/docs/rules/adjacent-overload-signatures.mdx +0 -105
- package/docs/rules/array-type.mdx +0 -126
- package/docs/rules/await-thenable.mdx +0 -184
- package/docs/rules/ban-ts-comment.mdx +0 -165
- package/docs/rules/ban-tslint-comment.mdx +0 -45
- package/docs/rules/ban-types.md +0 -26
- package/docs/rules/block-spacing.md +0 -15
- package/docs/rules/brace-style.md +0 -15
- package/docs/rules/camelcase.md +0 -15
- package/docs/rules/class-literal-property-style.mdx +0 -112
- package/docs/rules/class-methods-use-this.mdx +0 -135
- package/docs/rules/comma-dangle.md +0 -15
- package/docs/rules/comma-spacing.md +0 -15
- package/docs/rules/consistent-generic-constructors.mdx +0 -87
- package/docs/rules/consistent-indexed-object-style.mdx +0 -105
- package/docs/rules/consistent-return.mdx +0 -51
- package/docs/rules/consistent-type-assertions.mdx +0 -196
- package/docs/rules/consistent-type-definitions.mdx +0 -133
- package/docs/rules/consistent-type-exports.mdx +0 -97
- package/docs/rules/consistent-type-imports.mdx +0 -139
- package/docs/rules/default-param-last.mdx +0 -59
- package/docs/rules/dot-notation.mdx +0 -94
- package/docs/rules/explicit-function-return-type.mdx +0 -359
- package/docs/rules/explicit-member-accessibility.mdx +0 -353
- package/docs/rules/explicit-module-boundary-types.mdx +0 -287
- package/docs/rules/func-call-spacing.md +0 -15
- package/docs/rules/indent.md +0 -15
- package/docs/rules/init-declarations.mdx +0 -12
- package/docs/rules/key-spacing.md +0 -15
- package/docs/rules/keyword-spacing.md +0 -15
- package/docs/rules/lines-around-comment.md +0 -15
- package/docs/rules/lines-between-class-members.md +0 -15
- package/docs/rules/max-params.mdx +0 -54
- package/docs/rules/member-delimiter-style.md +0 -15
- package/docs/rules/member-ordering.mdx +0 -1483
- package/docs/rules/method-signature-style.mdx +0 -124
- package/docs/rules/naming-convention.mdx +0 -755
- package/docs/rules/no-array-constructor.mdx +0 -34
- package/docs/rules/no-array-delete.mdx +0 -44
- package/docs/rules/no-base-to-string.mdx +0 -115
- package/docs/rules/no-confusing-non-null-assertion.mdx +0 -75
- package/docs/rules/no-confusing-void-expression.mdx +0 -148
- package/docs/rules/no-deprecated.mdx +0 -119
- package/docs/rules/no-dupe-class-members.mdx +0 -16
- package/docs/rules/no-duplicate-enum-values.mdx +0 -66
- package/docs/rules/no-duplicate-imports.mdx +0 -17
- package/docs/rules/no-duplicate-type-constituents.mdx +0 -89
- package/docs/rules/no-dynamic-delete.mdx +0 -64
- package/docs/rules/no-empty-function.mdx +0 -94
- package/docs/rules/no-empty-interface.mdx +0 -75
- package/docs/rules/no-empty-object-type.mdx +0 -150
- package/docs/rules/no-explicit-any.mdx +0 -177
- package/docs/rules/no-extra-non-null-assertion.mdx +0 -60
- package/docs/rules/no-extra-parens.md +0 -15
- package/docs/rules/no-extra-semi.md +0 -15
- package/docs/rules/no-extraneous-class.mdx +0 -329
- package/docs/rules/no-floating-promises.mdx +0 -282
- package/docs/rules/no-for-in-array.mdx +0 -67
- package/docs/rules/no-implied-eval.mdx +0 -106
- package/docs/rules/no-import-type-side-effects.mdx +0 -80
- package/docs/rules/no-inferrable-types.mdx +0 -113
- package/docs/rules/no-invalid-this.mdx +0 -16
- package/docs/rules/no-invalid-void-type.mdx +0 -119
- package/docs/rules/no-loop-func.mdx +0 -12
- package/docs/rules/no-loss-of-precision.mdx +0 -17
- package/docs/rules/no-magic-numbers.mdx +0 -131
- package/docs/rules/no-meaningless-void-operator.mdx +0 -61
- package/docs/rules/no-misused-new.mdx +0 -53
- package/docs/rules/no-misused-promises.mdx +0 -314
- package/docs/rules/no-misused-spread.mdx +0 -132
- package/docs/rules/no-mixed-enums.mdx +0 -96
- package/docs/rules/no-namespace.mdx +0 -157
- package/docs/rules/no-non-null-asserted-nullish-coalescing.mdx +0 -60
- package/docs/rules/no-non-null-asserted-optional-chain.mdx +0 -46
- package/docs/rules/no-non-null-assertion.mdx +0 -48
- package/docs/rules/no-parameter-properties.mdx +0 -16
- package/docs/rules/no-redeclare.mdx +0 -79
- package/docs/rules/no-redundant-type-constituents.mdx +0 -102
- package/docs/rules/no-require-imports.mdx +0 -114
- package/docs/rules/no-restricted-imports.mdx +0 -84
- package/docs/rules/no-restricted-types.mdx +0 -70
- package/docs/rules/no-shadow.mdx +0 -143
- package/docs/rules/no-this-alias.mdx +0 -124
- package/docs/rules/no-type-alias.mdx +0 -626
- package/docs/rules/no-unnecessary-boolean-literal-compare.mdx +0 -165
- package/docs/rules/no-unnecessary-condition.mdx +0 -293
- package/docs/rules/no-unnecessary-parameter-property-assignment.mdx +0 -42
- package/docs/rules/no-unnecessary-qualifier.mdx +0 -57
- package/docs/rules/no-unnecessary-template-expression.mdx +0 -108
- package/docs/rules/no-unnecessary-type-arguments.mdx +0 -85
- package/docs/rules/no-unnecessary-type-assertion.mdx +0 -97
- package/docs/rules/no-unnecessary-type-constraint.mdx +0 -61
- package/docs/rules/no-unnecessary-type-conversion.mdx +0 -79
- package/docs/rules/no-unnecessary-type-parameters.mdx +0 -255
- package/docs/rules/no-unsafe-argument.mdx +0 -98
- package/docs/rules/no-unsafe-assignment.mdx +0 -101
- package/docs/rules/no-unsafe-call.mdx +0 -120
- package/docs/rules/no-unsafe-declaration-merging.mdx +0 -65
- package/docs/rules/no-unsafe-enum-comparison.mdx +0 -98
- package/docs/rules/no-unsafe-function-type.mdx +0 -65
- package/docs/rules/no-unsafe-member-access.mdx +0 -81
- package/docs/rules/no-unsafe-return.mdx +0 -126
- package/docs/rules/no-unsafe-type-assertion.mdx +0 -63
- package/docs/rules/no-unsafe-unary-minus.mdx +0 -60
- package/docs/rules/no-unused-expressions.mdx +0 -52
- package/docs/rules/no-unused-vars.mdx +0 -136
- package/docs/rules/no-use-before-define.mdx +0 -98
- package/docs/rules/no-useless-constructor.mdx +0 -21
- package/docs/rules/no-useless-empty-export.mdx +0 -53
- package/docs/rules/no-useless-template-literals.mdx +0 -9
- package/docs/rules/no-var-requires.mdx +0 -77
- package/docs/rules/no-wrapper-object-types.mdx +0 -75
- package/docs/rules/non-nullable-type-assertion-style.mdx +0 -47
- package/docs/rules/object-curly-spacing.md +0 -15
- package/docs/rules/only-throw-error.mdx +0 -150
- package/docs/rules/padding-line-between-statements.md +0 -15
- package/docs/rules/parameter-properties.mdx +0 -522
- package/docs/rules/prefer-as-const.mdx +0 -51
- package/docs/rules/prefer-destructuring.mdx +0 -101
- package/docs/rules/prefer-enum-initializers.mdx +0 -68
- package/docs/rules/prefer-find.mdx +0 -45
- package/docs/rules/prefer-for-of.mdx +0 -50
- package/docs/rules/prefer-function-type.mdx +0 -98
- package/docs/rules/prefer-includes.mdx +0 -81
- package/docs/rules/prefer-literal-enum-member.mdx +0 -111
- package/docs/rules/prefer-namespace-keyword.mdx +0 -51
- package/docs/rules/prefer-nullish-coalescing.mdx +0 -349
- package/docs/rules/prefer-optional-chain.mdx +0 -304
- package/docs/rules/prefer-promise-reject-errors.mdx +0 -78
- package/docs/rules/prefer-readonly-parameter-types.mdx +0 -408
- package/docs/rules/prefer-readonly.mdx +0 -111
- package/docs/rules/prefer-reduce-type-parameter.mdx +0 -66
- package/docs/rules/prefer-regexp-exec.mdx +0 -52
- package/docs/rules/prefer-return-this-type.mdx +0 -93
- package/docs/rules/prefer-string-starts-ends-with.mdx +0 -84
- package/docs/rules/prefer-ts-expect-error.mdx +0 -86
- package/docs/rules/promise-function-async.mdx +0 -143
- package/docs/rules/quotes.md +0 -15
- package/docs/rules/related-getter-setter-pairs.mdx +0 -61
- package/docs/rules/require-array-sort-compare.mdx +0 -89
- package/docs/rules/require-await.mdx +0 -53
- package/docs/rules/restrict-plus-operands.mdx +0 -245
- package/docs/rules/restrict-template-expressions.mdx +0 -167
- package/docs/rules/return-await.mdx +0 -339
- package/docs/rules/semi.md +0 -15
- package/docs/rules/sort-type-constituents.mdx +0 -209
- package/docs/rules/sort-type-union-intersection-members.mdx +0 -16
- package/docs/rules/space-before-blocks.md +0 -15
- package/docs/rules/space-before-function-paren.md +0 -15
- package/docs/rules/space-infix-ops.md +0 -15
- package/docs/rules/strict-boolean-expressions.mdx +0 -184
- package/docs/rules/switch-exhaustiveness-check.mdx +0 -280
- package/docs/rules/triple-slash-reference.mdx +0 -129
- package/docs/rules/type-annotation-spacing.md +0 -15
- package/docs/rules/typedef.mdx +0 -350
- package/docs/rules/unbound-method.mdx +0 -114
- package/docs/rules/unified-signatures.mdx +0 -132
- package/docs/rules/use-unknown-in-catch-callback-variable.mdx +0 -97
@@ -1,157 +0,0 @@
|
|
1
|
-
---
|
2
|
-
description: 'Disallow TypeScript namespaces.'
|
3
|
-
---
|
4
|
-
|
5
|
-
import Tabs from '@theme/Tabs';
|
6
|
-
import TabItem from '@theme/TabItem';
|
7
|
-
|
8
|
-
> 🛑 This file is source code, not the primary documentation location! 🛑
|
9
|
-
>
|
10
|
-
> See **https://typescript-eslint.io/rules/no-namespace** for documentation.
|
11
|
-
|
12
|
-
TypeScript historically allowed a form of code organization called "custom modules" (`module Example {}`), later renamed to "namespaces" (`namespace Example`).
|
13
|
-
Namespaces are an outdated way to organize TypeScript code.
|
14
|
-
ES2015 module syntax is now preferred (`import`/`export`).
|
15
|
-
|
16
|
-
> This rule does not report on the use of TypeScript module declarations to describe external APIs (`declare module 'foo' {}`).
|
17
|
-
|
18
|
-
## Examples
|
19
|
-
|
20
|
-
Examples of code with the default options:
|
21
|
-
|
22
|
-
<Tabs>
|
23
|
-
<TabItem value="❌ Incorrect">
|
24
|
-
|
25
|
-
```ts
|
26
|
-
module foo {}
|
27
|
-
namespace foo {}
|
28
|
-
|
29
|
-
declare module foo {}
|
30
|
-
declare namespace foo {}
|
31
|
-
```
|
32
|
-
|
33
|
-
</TabItem>
|
34
|
-
<TabItem value="✅ Correct">
|
35
|
-
|
36
|
-
```ts
|
37
|
-
declare module 'foo' {}
|
38
|
-
|
39
|
-
// anything inside a d.ts file
|
40
|
-
```
|
41
|
-
|
42
|
-
</TabItem>
|
43
|
-
</Tabs>
|
44
|
-
|
45
|
-
## Options
|
46
|
-
|
47
|
-
### `allowDeclarations`
|
48
|
-
|
49
|
-
{/* insert option description */}
|
50
|
-
|
51
|
-
Examples of code with the `{ "allowDeclarations": true }` option:
|
52
|
-
|
53
|
-
<Tabs>
|
54
|
-
<TabItem value="❌ Incorrect">
|
55
|
-
|
56
|
-
```ts option='{ "allowDeclarations": true }'
|
57
|
-
module foo {}
|
58
|
-
namespace foo {}
|
59
|
-
```
|
60
|
-
|
61
|
-
</TabItem>
|
62
|
-
<TabItem value="✅ Correct">
|
63
|
-
|
64
|
-
```ts option='{ "allowDeclarations": true }'
|
65
|
-
declare module 'foo' {}
|
66
|
-
declare module foo {}
|
67
|
-
declare namespace foo {}
|
68
|
-
|
69
|
-
declare global {
|
70
|
-
namespace foo {}
|
71
|
-
}
|
72
|
-
|
73
|
-
declare module foo {
|
74
|
-
namespace foo {}
|
75
|
-
}
|
76
|
-
```
|
77
|
-
|
78
|
-
</TabItem>
|
79
|
-
</Tabs>
|
80
|
-
|
81
|
-
Examples of code for the `{ "allowDeclarations": false }` option:
|
82
|
-
|
83
|
-
<Tabs>
|
84
|
-
<TabItem value="❌ Incorrect">
|
85
|
-
|
86
|
-
```ts option='{ "allowDeclarations": false }'
|
87
|
-
module foo {}
|
88
|
-
namespace foo {}
|
89
|
-
declare module foo {}
|
90
|
-
declare namespace foo {}
|
91
|
-
```
|
92
|
-
|
93
|
-
</TabItem>
|
94
|
-
<TabItem value="✅ Correct">
|
95
|
-
|
96
|
-
```ts option='{ "allowDeclarations": false }'
|
97
|
-
declare module 'foo' {}
|
98
|
-
```
|
99
|
-
|
100
|
-
</TabItem>
|
101
|
-
</Tabs>
|
102
|
-
|
103
|
-
### `allowDefinitionFiles`
|
104
|
-
|
105
|
-
{/* insert option description */}
|
106
|
-
|
107
|
-
Examples of code for the `{ "allowDefinitionFiles": true }` option:
|
108
|
-
|
109
|
-
<Tabs>
|
110
|
-
<TabItem value="❌ Incorrect">
|
111
|
-
|
112
|
-
```ts option='{ "allowDefinitionFiles": true }'
|
113
|
-
// if outside a d.ts file
|
114
|
-
module foo {}
|
115
|
-
namespace foo {}
|
116
|
-
|
117
|
-
// if outside a d.ts file and allowDeclarations = false
|
118
|
-
module foo {}
|
119
|
-
namespace foo {}
|
120
|
-
declare module foo {}
|
121
|
-
declare namespace foo {}
|
122
|
-
```
|
123
|
-
|
124
|
-
</TabItem>
|
125
|
-
<TabItem value="✅ Correct">
|
126
|
-
|
127
|
-
```ts option='{ "allowDefinitionFiles": true }'
|
128
|
-
declare module 'foo' {}
|
129
|
-
|
130
|
-
// anything inside a d.ts file
|
131
|
-
```
|
132
|
-
|
133
|
-
</TabItem>
|
134
|
-
</Tabs>
|
135
|
-
|
136
|
-
## When Not To Use It
|
137
|
-
|
138
|
-
If your project uses TypeScript's CommonJS export syntax (`export = ...`), you may need to use namespaces in order to export types from your module.
|
139
|
-
You can learn more about this at:
|
140
|
-
|
141
|
-
- [TypeScript#52203](https://github.com/microsoft/TypeScript/pull/52203), the pull request introducing [`verbatimModuleSyntax`](https://www.typescriptlang.org/tsconfig/#verbatimModuleSyntax)
|
142
|
-
- [TypeScript#60852](https://github.com/microsoft/TypeScript/issues/60852), an issue requesting syntax to export types from a CommonJS module.
|
143
|
-
|
144
|
-
If your project uses this syntax, either because it was architected before modern modules and namespaces, or because a module option such as `verbatimModuleSyntax` requires it, it may be difficult to migrate off of namespaces.
|
145
|
-
In that case you may not be able to use this rule for parts of your project.
|
146
|
-
|
147
|
-
You might consider using [ESLint disable comments](https://eslint.org/docs/latest/use/configure/rules#using-configuration-comments-1) for those specific situations instead of completely disabling this rule.
|
148
|
-
|
149
|
-
## Further Reading
|
150
|
-
|
151
|
-
{/* cspell:disable-next-line */}
|
152
|
-
|
153
|
-
- [FAQ: I get errors from the `@typescript-eslint/no-namespace` and/or `no-var` rules about declaring global variables](/troubleshooting/faqs/eslint#i-get-errors-from-the-typescript-eslintno-namespace-andor-no-var-rules-about-declaring-global-variables)
|
154
|
-
- [FAQ: How should I handle reports that conflict with verbatimModuleSyntax?](/troubleshooting/faqs/typescript#how-should-i-handle-reports-that-conflict-with-verbatimmodulesyntax)
|
155
|
-
- [TypeScript handbook entry on Modules](https://www.typescriptlang.org/docs/handbook/modules.html)
|
156
|
-
- [TypeScript handbook entry on Namespaces](https://www.typescriptlang.org/docs/handbook/namespaces.html)
|
157
|
-
- [TypeScript handbook entry on Namespaces and Modules](https://www.typescriptlang.org/docs/handbook/namespaces-and-modules.html)
|
@@ -1,60 +0,0 @@
|
|
1
|
-
---
|
2
|
-
description: 'Disallow non-null assertions in the left operand of a nullish coalescing operator.'
|
3
|
-
---
|
4
|
-
|
5
|
-
import Tabs from '@theme/Tabs';
|
6
|
-
import TabItem from '@theme/TabItem';
|
7
|
-
|
8
|
-
> 🛑 This file is source code, not the primary documentation location! 🛑
|
9
|
-
>
|
10
|
-
> See **https://typescript-eslint.io/rules/no-non-null-asserted-nullish-coalescing** for documentation.
|
11
|
-
|
12
|
-
The `??` nullish coalescing runtime operator allows providing a default value when dealing with `null` or `undefined`.
|
13
|
-
Using a `!` non-null assertion type operator in the left operand of a nullish coalescing operator is redundant, and likely a sign of programmer error or confusion over the two operators.
|
14
|
-
|
15
|
-
## Examples
|
16
|
-
|
17
|
-
<Tabs>
|
18
|
-
<TabItem value="❌ Incorrect">
|
19
|
-
|
20
|
-
```ts
|
21
|
-
foo! ?? bar;
|
22
|
-
foo.bazz! ?? bar;
|
23
|
-
foo!.bazz! ?? bar;
|
24
|
-
foo()! ?? bar;
|
25
|
-
|
26
|
-
let x!: string;
|
27
|
-
x! ?? '';
|
28
|
-
|
29
|
-
let x: string;
|
30
|
-
x = foo();
|
31
|
-
x! ?? '';
|
32
|
-
```
|
33
|
-
|
34
|
-
</TabItem>
|
35
|
-
<TabItem value="✅ Correct">
|
36
|
-
|
37
|
-
```ts
|
38
|
-
foo ?? bar;
|
39
|
-
foo ?? bar!;
|
40
|
-
foo!.bazz ?? bar;
|
41
|
-
foo!.bazz ?? bar!;
|
42
|
-
foo() ?? bar;
|
43
|
-
|
44
|
-
// This is considered correct code because there's no way for the user to satisfy it.
|
45
|
-
let x: string;
|
46
|
-
x! ?? '';
|
47
|
-
```
|
48
|
-
|
49
|
-
</TabItem>
|
50
|
-
</Tabs>
|
51
|
-
|
52
|
-
## When Not To Use It
|
53
|
-
|
54
|
-
If your project's types don't yet fully describe whether certain values may be nullable, such as if you're transitioning to `strictNullChecks`, this rule might create many false reports.
|
55
|
-
You might consider using [ESLint disable comments](https://eslint.org/docs/latest/use/configure/rules#using-configuration-comments-1) for those specific situations instead of completely disabling this rule.
|
56
|
-
|
57
|
-
## Further Reading
|
58
|
-
|
59
|
-
- [TypeScript 3.7 Release Notes](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html)
|
60
|
-
- [Nullish Coalescing Proposal](https://github.com/tc39/proposal-nullish-coalescing)
|
@@ -1,46 +0,0 @@
|
|
1
|
-
---
|
2
|
-
description: 'Disallow non-null assertions after an optional chain expression.'
|
3
|
-
---
|
4
|
-
|
5
|
-
import Tabs from '@theme/Tabs';
|
6
|
-
import TabItem from '@theme/TabItem';
|
7
|
-
|
8
|
-
> 🛑 This file is source code, not the primary documentation location! 🛑
|
9
|
-
>
|
10
|
-
> See **https://typescript-eslint.io/rules/no-non-null-asserted-optional-chain** for documentation.
|
11
|
-
|
12
|
-
`?.` optional chain expressions provide `undefined` if an object is `null` or `undefined`.
|
13
|
-
Using a `!` non-null assertion to assert the result of an `?.` optional chain expression is non-nullable is likely wrong.
|
14
|
-
|
15
|
-
> Most of the time, either the object was not nullable and did not need the `?.` for its property lookup, or the `!` is incorrect and introducing a type safety hole.
|
16
|
-
|
17
|
-
## Examples
|
18
|
-
|
19
|
-
<Tabs>
|
20
|
-
<TabItem value="❌ Incorrect">
|
21
|
-
|
22
|
-
```ts
|
23
|
-
foo?.bar!;
|
24
|
-
foo?.bar()!;
|
25
|
-
```
|
26
|
-
|
27
|
-
</TabItem>
|
28
|
-
<TabItem value="✅ Correct">
|
29
|
-
|
30
|
-
```ts
|
31
|
-
foo?.bar;
|
32
|
-
foo?.bar();
|
33
|
-
```
|
34
|
-
|
35
|
-
</TabItem>
|
36
|
-
</Tabs>
|
37
|
-
|
38
|
-
## When Not To Use It
|
39
|
-
|
40
|
-
If your project's types don't yet fully describe whether certain values may be nullable, such as if you're transitioning to `strictNullChecks`, this rule might create many false reports.
|
41
|
-
You might consider using [ESLint disable comments](https://eslint.org/docs/latest/use/configure/rules#using-configuration-comments-1) for those specific situations instead of completely disabling this rule.
|
42
|
-
|
43
|
-
## Further Reading
|
44
|
-
|
45
|
-
- [TypeScript 3.7 Release Notes](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html)
|
46
|
-
- [Optional Chaining Proposal](https://github.com/tc39/proposal-optional-chaining/)
|
@@ -1,48 +0,0 @@
|
|
1
|
-
---
|
2
|
-
description: 'Disallow non-null assertions using the `!` postfix operator.'
|
3
|
-
---
|
4
|
-
|
5
|
-
import Tabs from '@theme/Tabs';
|
6
|
-
import TabItem from '@theme/TabItem';
|
7
|
-
|
8
|
-
> 🛑 This file is source code, not the primary documentation location! 🛑
|
9
|
-
>
|
10
|
-
> See **https://typescript-eslint.io/rules/no-non-null-assertion** for documentation.
|
11
|
-
|
12
|
-
TypeScript's `!` non-null assertion operator asserts to the type system that an expression is non-nullable, as in not `null` or `undefined`.
|
13
|
-
Using assertions to tell the type system new information is often a sign that code is not fully type-safe.
|
14
|
-
It's generally better to structure program logic so that TypeScript understands when values may be nullable.
|
15
|
-
|
16
|
-
## Examples
|
17
|
-
|
18
|
-
<Tabs>
|
19
|
-
<TabItem value="❌ Incorrect">
|
20
|
-
|
21
|
-
```ts
|
22
|
-
interface Example {
|
23
|
-
property?: string;
|
24
|
-
}
|
25
|
-
|
26
|
-
declare const example: Example;
|
27
|
-
const includesBaz = example.property!.includes('baz');
|
28
|
-
```
|
29
|
-
|
30
|
-
</TabItem>
|
31
|
-
<TabItem value="✅ Correct">
|
32
|
-
|
33
|
-
```ts
|
34
|
-
interface Example {
|
35
|
-
property?: string;
|
36
|
-
}
|
37
|
-
|
38
|
-
declare const example: Example;
|
39
|
-
const includesBaz = example.property?.includes('baz') ?? false;
|
40
|
-
```
|
41
|
-
|
42
|
-
</TabItem>
|
43
|
-
</Tabs>
|
44
|
-
|
45
|
-
## When Not To Use It
|
46
|
-
|
47
|
-
If your project's types don't yet fully describe whether certain values may be nullable, such as if you're transitioning to `strictNullChecks`, this rule might create many false reports.
|
48
|
-
You might consider using [ESLint disable comments](https://eslint.org/docs/latest/use/configure/rules#using-configuration-comments-1) for those specific situations instead of completely disabling this rule.
|
@@ -1,16 +0,0 @@
|
|
1
|
-
---
|
2
|
-
displayed_sidebar: rulesSidebar
|
3
|
-
---
|
4
|
-
|
5
|
-
:::danger Deprecated
|
6
|
-
|
7
|
-
This rule has been deprecated in favour of the [`parameter-properties`](https://typescript-eslint.io/rules/parameter-properties/) rule.
|
8
|
-
|
9
|
-
:::
|
10
|
-
|
11
|
-
<!--
|
12
|
-
This doc file has been left on purpose to help direct people to the replacement rule.
|
13
|
-
|
14
|
-
Note that there is no actual way to get to this page in the normal navigation,
|
15
|
-
so end-users will only be able to get to this page from the search bar.
|
16
|
-
-->
|
@@ -1,79 +0,0 @@
|
|
1
|
-
---
|
2
|
-
description: 'Disallow variable redeclaration.'
|
3
|
-
---
|
4
|
-
|
5
|
-
import Tabs from '@theme/Tabs';
|
6
|
-
import TabItem from '@theme/TabItem';
|
7
|
-
|
8
|
-
> 🛑 This file is source code, not the primary documentation location! 🛑
|
9
|
-
>
|
10
|
-
> See **https://typescript-eslint.io/rules/no-redeclare** for documentation.
|
11
|
-
|
12
|
-
import TypeScriptOverlap from '@site/src/components/TypeScriptOverlap';
|
13
|
-
|
14
|
-
<TypeScriptOverlap />
|
15
|
-
|
16
|
-
It adds support for TypeScript function overloads, and declaration merging.
|
17
|
-
|
18
|
-
## Options
|
19
|
-
|
20
|
-
This rule adds the following options:
|
21
|
-
|
22
|
-
```ts
|
23
|
-
interface Options extends BaseNoRedeclareOptions {
|
24
|
-
ignoreDeclarationMerge?: boolean;
|
25
|
-
}
|
26
|
-
|
27
|
-
const defaultOptions: Options = {
|
28
|
-
...baseNoRedeclareDefaultOptions,
|
29
|
-
ignoreDeclarationMerge: true,
|
30
|
-
};
|
31
|
-
```
|
32
|
-
|
33
|
-
### `ignoreDeclarationMerge`
|
34
|
-
|
35
|
-
{/* insert option description */}
|
36
|
-
|
37
|
-
The following sets will be ignored when this option is enabled:
|
38
|
-
|
39
|
-
- interface + interface
|
40
|
-
- namespace + namespace
|
41
|
-
- class + interface
|
42
|
-
- class + namespace
|
43
|
-
- class + interface + namespace
|
44
|
-
- function + namespace
|
45
|
-
- enum + namespace
|
46
|
-
|
47
|
-
Examples of **correct** code with `{ ignoreDeclarationMerge: true }`:
|
48
|
-
|
49
|
-
```ts option='{ "ignoreDeclarationMerge": true }' showPlaygroundButton
|
50
|
-
interface A {
|
51
|
-
prop1: 1;
|
52
|
-
}
|
53
|
-
interface A {
|
54
|
-
prop2: 2;
|
55
|
-
}
|
56
|
-
|
57
|
-
namespace Foo {
|
58
|
-
export const a = 1;
|
59
|
-
}
|
60
|
-
namespace Foo {
|
61
|
-
export const b = 2;
|
62
|
-
}
|
63
|
-
|
64
|
-
class Bar {}
|
65
|
-
namespace Bar {}
|
66
|
-
|
67
|
-
function Baz() {}
|
68
|
-
namespace Baz {}
|
69
|
-
```
|
70
|
-
|
71
|
-
**Note:** Even with this option set to true, this rule will report if you name a type and a variable the same name. **_This is intentional_**.
|
72
|
-
Declaring a variable and a type the same is usually an accident, and it can lead to hard-to-understand code.
|
73
|
-
If you have a rare case where you're intentionally naming a type the same name as a variable, use a disable comment. For example:
|
74
|
-
|
75
|
-
```ts option='{ "ignoreDeclarationMerge": true }' showPlaygroundButton
|
76
|
-
type something = string;
|
77
|
-
// eslint-disable-next-line @typescript-eslint/no-redeclare -- intentionally naming the variable the same as the type
|
78
|
-
const something = 2;
|
79
|
-
```
|
@@ -1,102 +0,0 @@
|
|
1
|
-
---
|
2
|
-
description: 'Disallow members of unions and intersections that do nothing or override type information.'
|
3
|
-
---
|
4
|
-
|
5
|
-
import Tabs from '@theme/Tabs';
|
6
|
-
import TabItem from '@theme/TabItem';
|
7
|
-
|
8
|
-
> 🛑 This file is source code, not the primary documentation location! 🛑
|
9
|
-
>
|
10
|
-
> See **https://typescript-eslint.io/rules/no-redundant-type-constituents** for documentation.
|
11
|
-
|
12
|
-
Some types can override some other types ("constituents") in a union or intersection and/or be overridden by some other types.
|
13
|
-
TypeScript's set theory of types includes cases where a constituent type might be useless in the parent union or intersection.
|
14
|
-
|
15
|
-
Within `|` unions:
|
16
|
-
|
17
|
-
- `any` and `unknown` "override" all other union members
|
18
|
-
- `never` is dropped from unions in any position except when in a return type position
|
19
|
-
- primitive types such as `string` "override" any of their literal types such as `""`
|
20
|
-
|
21
|
-
Within `&` intersections:
|
22
|
-
|
23
|
-
- `any` and `never` "override" all other intersection members
|
24
|
-
- `unknown` is dropped from intersections
|
25
|
-
- literal types "override" any primitive types in an intersection
|
26
|
-
- literal types such as `""` "override" any of their primitive types such as `string`
|
27
|
-
|
28
|
-
## Examples
|
29
|
-
|
30
|
-
<Tabs>
|
31
|
-
<TabItem value="❌ Incorrect">
|
32
|
-
|
33
|
-
```ts
|
34
|
-
type UnionAny = any | 'foo';
|
35
|
-
type UnionUnknown = unknown | 'foo';
|
36
|
-
type UnionNever = never | 'foo';
|
37
|
-
|
38
|
-
type UnionBooleanLiteral = boolean | false;
|
39
|
-
type UnionNumberLiteral = number | 1;
|
40
|
-
type UnionStringLiteral = string | 'foo';
|
41
|
-
|
42
|
-
type IntersectionAny = any & 'foo';
|
43
|
-
type IntersectionUnknown = string & unknown;
|
44
|
-
type IntersectionNever = string | never;
|
45
|
-
|
46
|
-
type IntersectionBooleanLiteral = boolean & false;
|
47
|
-
type IntersectionNumberLiteral = number & 1;
|
48
|
-
type IntersectionStringLiteral = string & 'foo';
|
49
|
-
```
|
50
|
-
|
51
|
-
</TabItem>
|
52
|
-
<TabItem value="✅ Correct">
|
53
|
-
|
54
|
-
```ts
|
55
|
-
type UnionAny = any;
|
56
|
-
type UnionUnknown = unknown;
|
57
|
-
type UnionNever = never;
|
58
|
-
|
59
|
-
type UnionBooleanLiteral = boolean;
|
60
|
-
type UnionNumberLiteral = number;
|
61
|
-
type UnionStringLiteral = string;
|
62
|
-
|
63
|
-
type IntersectionAny = any;
|
64
|
-
type IntersectionUnknown = string;
|
65
|
-
type IntersectionNever = string;
|
66
|
-
|
67
|
-
type IntersectionBooleanLiteral = false;
|
68
|
-
type IntersectionNumberLiteral = 1;
|
69
|
-
type IntersectionStringLiteral = 'foo';
|
70
|
-
```
|
71
|
-
|
72
|
-
</TabItem>
|
73
|
-
</Tabs>
|
74
|
-
|
75
|
-
## Limitations
|
76
|
-
|
77
|
-
This rule plays it safe and only works with bottom types, top types, and comparing literal types to primitive types.
|
78
|
-
|
79
|
-
## When Not To Use It
|
80
|
-
|
81
|
-
Some projects choose to occasionally intentionally include a redundant type constituent for documentation purposes.
|
82
|
-
For example, the following code includes `string` in a union even though the `unknown` makes it redundant:
|
83
|
-
|
84
|
-
```ts
|
85
|
-
/**
|
86
|
-
* Normally a string name, but sometimes arbitrary unknown data.
|
87
|
-
*/
|
88
|
-
type NameOrOther = string | unknown;
|
89
|
-
```
|
90
|
-
|
91
|
-
If you strongly feel a preference for these unnecessary type constituents, this rule might not be for you.
|
92
|
-
|
93
|
-
## Further Reading
|
94
|
-
|
95
|
-
- [Union Types](https://www.typescriptlang.org/docs/handbook/2/everyday-types.html#union-types)
|
96
|
-
- [Intersection Types](https://www.typescriptlang.org/docs/handbook/2/objects.html#intersection-types)
|
97
|
-
- [Bottom Types](https://en.wikipedia.org/wiki/Bottom_type)
|
98
|
-
- [Top Types](https://en.wikipedia.org/wiki/Top_type)
|
99
|
-
|
100
|
-
## Related To
|
101
|
-
|
102
|
-
- [no-duplicate-type-constituents](./no-duplicate-type-constituents.mdx)
|
@@ -1,114 +0,0 @@
|
|
1
|
-
---
|
2
|
-
description: 'Disallow invocation of `require()`.'
|
3
|
-
---
|
4
|
-
|
5
|
-
import Tabs from '@theme/Tabs';
|
6
|
-
import TabItem from '@theme/TabItem';
|
7
|
-
|
8
|
-
> 🛑 This file is source code, not the primary documentation location! 🛑
|
9
|
-
>
|
10
|
-
> See **https://typescript-eslint.io/rules/no-require-imports** for documentation.
|
11
|
-
|
12
|
-
Depending on your TSConfig settings and whether you're authoring ES Modules or CommonJS, TS may allow both `import` and `require()` to be used, even within a single file.
|
13
|
-
|
14
|
-
This rule enforces that you use the newer ES Module `import` syntax over CommonJS `require()`.
|
15
|
-
|
16
|
-
## Examples
|
17
|
-
|
18
|
-
<Tabs>
|
19
|
-
<TabItem value="❌ Incorrect">
|
20
|
-
|
21
|
-
```ts
|
22
|
-
const lib1 = require('lib1');
|
23
|
-
const { lib2 } = require('lib2');
|
24
|
-
import lib3 = require('lib3');
|
25
|
-
```
|
26
|
-
|
27
|
-
</TabItem>
|
28
|
-
<TabItem value="✅ Correct">
|
29
|
-
|
30
|
-
```ts
|
31
|
-
import * as lib1 from 'lib1';
|
32
|
-
import { lib2 } from 'lib2';
|
33
|
-
import * as lib3 from 'lib3';
|
34
|
-
```
|
35
|
-
|
36
|
-
</TabItem>
|
37
|
-
</Tabs>
|
38
|
-
|
39
|
-
## Options
|
40
|
-
|
41
|
-
### `allow`
|
42
|
-
|
43
|
-
{/* insert option description */}
|
44
|
-
|
45
|
-
These strings will be compiled into regular expressions with the `u` flag and be used to test against the imported path. A common use case is to allow importing `package.json`. This is because `package.json` commonly lives outside of the TS root directory, so statically importing it would lead to root directory conflicts, especially with `resolveJsonModule` enabled. You can also use it to allow importing any JSON if your environment doesn't support JSON modules, or use it for other cases where `import` statements cannot work.
|
46
|
-
|
47
|
-
With `{ allow: ['/package\\.json$'] }`:
|
48
|
-
|
49
|
-
<Tabs>
|
50
|
-
<TabItem value="❌ Incorrect">
|
51
|
-
|
52
|
-
```ts option='{ "allow": ["/package.json$"] }'
|
53
|
-
console.log(require('../data.json').version);
|
54
|
-
```
|
55
|
-
|
56
|
-
</TabItem>
|
57
|
-
<TabItem value="✅ Correct">
|
58
|
-
|
59
|
-
```ts option='{ "allow": ["/package.json$"] }'
|
60
|
-
console.log(require('../package.json').version);
|
61
|
-
```
|
62
|
-
|
63
|
-
</TabItem>
|
64
|
-
</Tabs>
|
65
|
-
|
66
|
-
### `allowAsImport`
|
67
|
-
|
68
|
-
{/* insert option description */}
|
69
|
-
|
70
|
-
When set to `true`, `import ... = require(...)` declarations won't be reported.
|
71
|
-
This is beneficial if you use certain module options that require strict CommonJS interop semantics, such as [verbatimModuleSyntax](https://www.typescriptlang.org/tsconfig/#verbatimModuleSyntax).
|
72
|
-
|
73
|
-
With `{ allowAsImport: true }`:
|
74
|
-
|
75
|
-
<Tabs>
|
76
|
-
<TabItem value="❌ Incorrect">
|
77
|
-
|
78
|
-
```ts option='{ "allowAsImport": true }'
|
79
|
-
var foo = require('foo');
|
80
|
-
const foo = require('foo');
|
81
|
-
let foo = require('foo');
|
82
|
-
```
|
83
|
-
|
84
|
-
</TabItem>
|
85
|
-
<TabItem value="✅ Correct">
|
86
|
-
|
87
|
-
```ts option='{ "allowAsImport": true }'
|
88
|
-
import foo = require('foo');
|
89
|
-
import foo from 'foo';
|
90
|
-
```
|
91
|
-
|
92
|
-
</TabItem>
|
93
|
-
</Tabs>
|
94
|
-
|
95
|
-
## Usage with CommonJS
|
96
|
-
|
97
|
-
While this rule is primarily intended to promote ES Module syntax, it still makes sense to enable this rule when authoring CommonJS modules.
|
98
|
-
|
99
|
-
If you prefer to use TypeScript's built-in `import ... from ...` ES Module syntax, which is transformed to `require()` calls during transpilation when outputting CommonJS, you can use the rule's default behavior.
|
100
|
-
|
101
|
-
If, instead, you prefer to use `require()` syntax, we recommend you use this rule with [`allowAsImport`](#allowAsImport) enabled.
|
102
|
-
That way, you still enforce usage of `import ... = require(...)` rather than bare `require()` calls, which are not statically analyzed by TypeScript.
|
103
|
-
We don't directly a way to _prohibit_ ES Module syntax from being used; consider instead using TypeScript's [`verbatimModuleSyntax`](https://www.typescriptlang.org/tsconfig/#verbatimModuleSyntax) option if you find yourself in a situation where you would want this.
|
104
|
-
|
105
|
-
## When Not To Use It
|
106
|
-
|
107
|
-
If you are authoring CommonJS modules _and_ your project frequently uses dynamic `require`s, then this rule might not be applicable to you.
|
108
|
-
Otherwise the `allowAsImport` option probably suits your needs.
|
109
|
-
|
110
|
-
If only a subset of your project uses dynamic `require`s then you might consider using [ESLint disable comments](https://eslint.org/docs/latest/use/configure/rules#using-configuration-comments-1) for those specific situations instead of completely disabling this rule.
|
111
|
-
|
112
|
-
## Related To
|
113
|
-
|
114
|
-
- [`no-var-requires`](./no-var-requires.mdx)
|