@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.
Files changed (161) hide show
  1. package/package.json +9 -10
  2. package/docs/rules/README.md +0 -57
  3. package/docs/rules/TEMPLATE.md +0 -36
  4. package/docs/rules/adjacent-overload-signatures.mdx +0 -105
  5. package/docs/rules/array-type.mdx +0 -126
  6. package/docs/rules/await-thenable.mdx +0 -184
  7. package/docs/rules/ban-ts-comment.mdx +0 -165
  8. package/docs/rules/ban-tslint-comment.mdx +0 -45
  9. package/docs/rules/ban-types.md +0 -26
  10. package/docs/rules/block-spacing.md +0 -15
  11. package/docs/rules/brace-style.md +0 -15
  12. package/docs/rules/camelcase.md +0 -15
  13. package/docs/rules/class-literal-property-style.mdx +0 -112
  14. package/docs/rules/class-methods-use-this.mdx +0 -135
  15. package/docs/rules/comma-dangle.md +0 -15
  16. package/docs/rules/comma-spacing.md +0 -15
  17. package/docs/rules/consistent-generic-constructors.mdx +0 -87
  18. package/docs/rules/consistent-indexed-object-style.mdx +0 -105
  19. package/docs/rules/consistent-return.mdx +0 -51
  20. package/docs/rules/consistent-type-assertions.mdx +0 -196
  21. package/docs/rules/consistent-type-definitions.mdx +0 -133
  22. package/docs/rules/consistent-type-exports.mdx +0 -97
  23. package/docs/rules/consistent-type-imports.mdx +0 -139
  24. package/docs/rules/default-param-last.mdx +0 -59
  25. package/docs/rules/dot-notation.mdx +0 -94
  26. package/docs/rules/explicit-function-return-type.mdx +0 -359
  27. package/docs/rules/explicit-member-accessibility.mdx +0 -353
  28. package/docs/rules/explicit-module-boundary-types.mdx +0 -287
  29. package/docs/rules/func-call-spacing.md +0 -15
  30. package/docs/rules/indent.md +0 -15
  31. package/docs/rules/init-declarations.mdx +0 -12
  32. package/docs/rules/key-spacing.md +0 -15
  33. package/docs/rules/keyword-spacing.md +0 -15
  34. package/docs/rules/lines-around-comment.md +0 -15
  35. package/docs/rules/lines-between-class-members.md +0 -15
  36. package/docs/rules/max-params.mdx +0 -54
  37. package/docs/rules/member-delimiter-style.md +0 -15
  38. package/docs/rules/member-ordering.mdx +0 -1483
  39. package/docs/rules/method-signature-style.mdx +0 -124
  40. package/docs/rules/naming-convention.mdx +0 -755
  41. package/docs/rules/no-array-constructor.mdx +0 -34
  42. package/docs/rules/no-array-delete.mdx +0 -44
  43. package/docs/rules/no-base-to-string.mdx +0 -115
  44. package/docs/rules/no-confusing-non-null-assertion.mdx +0 -75
  45. package/docs/rules/no-confusing-void-expression.mdx +0 -148
  46. package/docs/rules/no-deprecated.mdx +0 -119
  47. package/docs/rules/no-dupe-class-members.mdx +0 -16
  48. package/docs/rules/no-duplicate-enum-values.mdx +0 -66
  49. package/docs/rules/no-duplicate-imports.mdx +0 -17
  50. package/docs/rules/no-duplicate-type-constituents.mdx +0 -89
  51. package/docs/rules/no-dynamic-delete.mdx +0 -64
  52. package/docs/rules/no-empty-function.mdx +0 -94
  53. package/docs/rules/no-empty-interface.mdx +0 -75
  54. package/docs/rules/no-empty-object-type.mdx +0 -150
  55. package/docs/rules/no-explicit-any.mdx +0 -177
  56. package/docs/rules/no-extra-non-null-assertion.mdx +0 -60
  57. package/docs/rules/no-extra-parens.md +0 -15
  58. package/docs/rules/no-extra-semi.md +0 -15
  59. package/docs/rules/no-extraneous-class.mdx +0 -329
  60. package/docs/rules/no-floating-promises.mdx +0 -282
  61. package/docs/rules/no-for-in-array.mdx +0 -67
  62. package/docs/rules/no-implied-eval.mdx +0 -106
  63. package/docs/rules/no-import-type-side-effects.mdx +0 -80
  64. package/docs/rules/no-inferrable-types.mdx +0 -113
  65. package/docs/rules/no-invalid-this.mdx +0 -16
  66. package/docs/rules/no-invalid-void-type.mdx +0 -119
  67. package/docs/rules/no-loop-func.mdx +0 -12
  68. package/docs/rules/no-loss-of-precision.mdx +0 -17
  69. package/docs/rules/no-magic-numbers.mdx +0 -131
  70. package/docs/rules/no-meaningless-void-operator.mdx +0 -61
  71. package/docs/rules/no-misused-new.mdx +0 -53
  72. package/docs/rules/no-misused-promises.mdx +0 -314
  73. package/docs/rules/no-misused-spread.mdx +0 -132
  74. package/docs/rules/no-mixed-enums.mdx +0 -96
  75. package/docs/rules/no-namespace.mdx +0 -157
  76. package/docs/rules/no-non-null-asserted-nullish-coalescing.mdx +0 -60
  77. package/docs/rules/no-non-null-asserted-optional-chain.mdx +0 -46
  78. package/docs/rules/no-non-null-assertion.mdx +0 -48
  79. package/docs/rules/no-parameter-properties.mdx +0 -16
  80. package/docs/rules/no-redeclare.mdx +0 -79
  81. package/docs/rules/no-redundant-type-constituents.mdx +0 -102
  82. package/docs/rules/no-require-imports.mdx +0 -114
  83. package/docs/rules/no-restricted-imports.mdx +0 -84
  84. package/docs/rules/no-restricted-types.mdx +0 -70
  85. package/docs/rules/no-shadow.mdx +0 -143
  86. package/docs/rules/no-this-alias.mdx +0 -124
  87. package/docs/rules/no-type-alias.mdx +0 -626
  88. package/docs/rules/no-unnecessary-boolean-literal-compare.mdx +0 -165
  89. package/docs/rules/no-unnecessary-condition.mdx +0 -293
  90. package/docs/rules/no-unnecessary-parameter-property-assignment.mdx +0 -42
  91. package/docs/rules/no-unnecessary-qualifier.mdx +0 -57
  92. package/docs/rules/no-unnecessary-template-expression.mdx +0 -108
  93. package/docs/rules/no-unnecessary-type-arguments.mdx +0 -85
  94. package/docs/rules/no-unnecessary-type-assertion.mdx +0 -97
  95. package/docs/rules/no-unnecessary-type-constraint.mdx +0 -61
  96. package/docs/rules/no-unnecessary-type-conversion.mdx +0 -79
  97. package/docs/rules/no-unnecessary-type-parameters.mdx +0 -255
  98. package/docs/rules/no-unsafe-argument.mdx +0 -98
  99. package/docs/rules/no-unsafe-assignment.mdx +0 -101
  100. package/docs/rules/no-unsafe-call.mdx +0 -120
  101. package/docs/rules/no-unsafe-declaration-merging.mdx +0 -65
  102. package/docs/rules/no-unsafe-enum-comparison.mdx +0 -98
  103. package/docs/rules/no-unsafe-function-type.mdx +0 -65
  104. package/docs/rules/no-unsafe-member-access.mdx +0 -81
  105. package/docs/rules/no-unsafe-return.mdx +0 -126
  106. package/docs/rules/no-unsafe-type-assertion.mdx +0 -63
  107. package/docs/rules/no-unsafe-unary-minus.mdx +0 -60
  108. package/docs/rules/no-unused-expressions.mdx +0 -52
  109. package/docs/rules/no-unused-vars.mdx +0 -136
  110. package/docs/rules/no-use-before-define.mdx +0 -98
  111. package/docs/rules/no-useless-constructor.mdx +0 -21
  112. package/docs/rules/no-useless-empty-export.mdx +0 -53
  113. package/docs/rules/no-useless-template-literals.mdx +0 -9
  114. package/docs/rules/no-var-requires.mdx +0 -77
  115. package/docs/rules/no-wrapper-object-types.mdx +0 -75
  116. package/docs/rules/non-nullable-type-assertion-style.mdx +0 -47
  117. package/docs/rules/object-curly-spacing.md +0 -15
  118. package/docs/rules/only-throw-error.mdx +0 -150
  119. package/docs/rules/padding-line-between-statements.md +0 -15
  120. package/docs/rules/parameter-properties.mdx +0 -522
  121. package/docs/rules/prefer-as-const.mdx +0 -51
  122. package/docs/rules/prefer-destructuring.mdx +0 -101
  123. package/docs/rules/prefer-enum-initializers.mdx +0 -68
  124. package/docs/rules/prefer-find.mdx +0 -45
  125. package/docs/rules/prefer-for-of.mdx +0 -50
  126. package/docs/rules/prefer-function-type.mdx +0 -98
  127. package/docs/rules/prefer-includes.mdx +0 -81
  128. package/docs/rules/prefer-literal-enum-member.mdx +0 -111
  129. package/docs/rules/prefer-namespace-keyword.mdx +0 -51
  130. package/docs/rules/prefer-nullish-coalescing.mdx +0 -349
  131. package/docs/rules/prefer-optional-chain.mdx +0 -304
  132. package/docs/rules/prefer-promise-reject-errors.mdx +0 -78
  133. package/docs/rules/prefer-readonly-parameter-types.mdx +0 -408
  134. package/docs/rules/prefer-readonly.mdx +0 -111
  135. package/docs/rules/prefer-reduce-type-parameter.mdx +0 -66
  136. package/docs/rules/prefer-regexp-exec.mdx +0 -52
  137. package/docs/rules/prefer-return-this-type.mdx +0 -93
  138. package/docs/rules/prefer-string-starts-ends-with.mdx +0 -84
  139. package/docs/rules/prefer-ts-expect-error.mdx +0 -86
  140. package/docs/rules/promise-function-async.mdx +0 -143
  141. package/docs/rules/quotes.md +0 -15
  142. package/docs/rules/related-getter-setter-pairs.mdx +0 -61
  143. package/docs/rules/require-array-sort-compare.mdx +0 -89
  144. package/docs/rules/require-await.mdx +0 -53
  145. package/docs/rules/restrict-plus-operands.mdx +0 -245
  146. package/docs/rules/restrict-template-expressions.mdx +0 -167
  147. package/docs/rules/return-await.mdx +0 -339
  148. package/docs/rules/semi.md +0 -15
  149. package/docs/rules/sort-type-constituents.mdx +0 -209
  150. package/docs/rules/sort-type-union-intersection-members.mdx +0 -16
  151. package/docs/rules/space-before-blocks.md +0 -15
  152. package/docs/rules/space-before-function-paren.md +0 -15
  153. package/docs/rules/space-infix-ops.md +0 -15
  154. package/docs/rules/strict-boolean-expressions.mdx +0 -184
  155. package/docs/rules/switch-exhaustiveness-check.mdx +0 -280
  156. package/docs/rules/triple-slash-reference.mdx +0 -129
  157. package/docs/rules/type-annotation-spacing.md +0 -15
  158. package/docs/rules/typedef.mdx +0 -350
  159. package/docs/rules/unbound-method.mdx +0 -114
  160. package/docs/rules/unified-signatures.mdx +0 -132
  161. package/docs/rules/use-unknown-in-catch-callback-variable.mdx +0 -97
@@ -1,626 +0,0 @@
1
- ---
2
- description: 'Disallow type aliases.'
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-type-alias** for documentation.
11
-
12
- :::danger Deprecated
13
-
14
- This rule has been deprecated in favour of the [`@typescript-eslint/consistent-type-definitions`](./consistent-type-definitions.mdx) rule.
15
- TypeScript type aliases are a commonly necessary language feature; banning it altogether is oftentimes counterproductive.
16
-
17
- :::
18
-
19
- :::note
20
-
21
- If you want to ban certain classifications of type aliases, consider using [`no-restricted-syntax`](https://eslint.org/docs/latest/rules/no-restricted-syntax).
22
- See [Troubleshooting & FAQs](/troubleshooting/faqs/general#how-can-i-ban-specific-language-feature).
23
-
24
- :::
25
-
26
- In TypeScript, type aliases serve three purposes:
27
-
28
- - Aliasing other types so that we can refer to them using a simpler name.
29
-
30
- ```ts
31
- // this...
32
- type Person = {
33
- firstName: string;
34
- lastName: string;
35
- age: number;
36
- };
37
-
38
- function addPerson(person: Person) {
39
- // ...
40
- }
41
-
42
- // is easier to read than this...
43
- function addPerson(person: {
44
- firstName: string;
45
- lastName: string;
46
- age: number;
47
- }) {
48
- // ...
49
- }
50
- ```
51
-
52
- - Act sort of like an interface, providing a set of methods and properties that must exist
53
- in the objects implementing the type.
54
-
55
- ```ts
56
- type Person = {
57
- firstName: string;
58
- lastName: string;
59
- age: number;
60
- walk: () => void;
61
- talk: () => void;
62
- };
63
-
64
- // you know person will have 3 properties and 2 methods,
65
- // because the structure has already been defined.
66
- var person: Person = {
67
- // ...
68
- };
69
-
70
- // so we can be sure that this will work
71
- person.walk();
72
- ```
73
-
74
- - Act like mapping tools between types to allow quick modifications.
75
-
76
- ```ts
77
- type Immutable<T> = { readonly [P in keyof T]: T[P] };
78
-
79
- type Person = {
80
- name: string;
81
- age: number;
82
- };
83
-
84
- type ImmutablePerson = Immutable<Person>;
85
-
86
- var person: ImmutablePerson = { name: 'John', age: 30 };
87
- person.name = 'Brad'; // error, readonly property
88
- ```
89
-
90
- When aliasing, the type alias does not create a new type, it just creates a new name
91
- to refer to the original type. So aliasing primitives and other simple types, tuples, unions
92
- or intersections can some times be redundant.
93
-
94
- ```ts
95
- // this doesn't make much sense
96
- type myString = string;
97
- ```
98
-
99
- On the other hand, using a type alias as an interface can limit your ability to:
100
-
101
- - Reuse your code: interfaces can be extended or implemented by other types. Type aliases cannot.
102
- - Debug your code: interfaces create a new name, so is easy to identify the base type of an object
103
- while debugging the application.
104
-
105
- Finally, mapping types is an advanced technique and leaving it open can quickly become a pain point
106
- in your application.
107
-
108
- ## Examples
109
-
110
- This rule disallows the use of type aliases in favor of interfaces
111
- and simplified types (primitives, tuples, unions, intersections, etc).
112
-
113
- ## Options
114
-
115
- ### `allowAliases`
116
-
117
- {/* insert option description */}
118
-
119
- The setting accepts the following values:
120
-
121
- - `"always"` or `"never"` to active or deactivate the feature.
122
- - `"in-unions"`, allows aliasing in union statements, e.g. `type Foo = string | string[];`
123
- - `"in-intersections"`, allows aliasing in intersection statements, e.g. `type Foo = string & string[];`
124
- - `"in-unions-and-intersections"`, allows aliasing in union and/or intersection statements.
125
-
126
- Examples of **correct** code for the `{ "allowAliases": "always" }` options:
127
-
128
- ```ts option='{ "allowAliases": "always" }' showPlaygroundButton
129
- // primitives
130
- type Foo = 'a';
131
-
132
- type Foo = 'a' | 'b';
133
-
134
- type Foo = string;
135
-
136
- type Foo = string | string[];
137
-
138
- type Foo = string & string[];
139
-
140
- type Foo = `foo-${number}`;
141
-
142
- // reference types
143
- interface Bar {}
144
- class Baz implements Bar {}
145
-
146
- type Foo = Bar;
147
-
148
- type Foo = Bar | Baz;
149
-
150
- type Foo = Bar & Baz;
151
- ```
152
-
153
- Examples of **incorrect** code for the `{ "allowAliases": "in-unions" }` option:
154
-
155
- ```ts option='{ "allowAliases": "in-unions" }' showPlaygroundButton
156
- // primitives
157
- type Foo = 'a';
158
-
159
- type Foo = string;
160
-
161
- type Foo = string & string[];
162
-
163
- type Foo = `foo-${number}`;
164
-
165
- // reference types
166
- interface Bar {}
167
- class Baz implements Bar {}
168
-
169
- type Foo = Bar;
170
-
171
- type Foo = Bar & Baz;
172
- ```
173
-
174
- Examples of **correct** code for the `{ "allowAliases": "in-unions" }` option:
175
-
176
- ```ts option='{ "allowAliases": "in-unions" }' showPlaygroundButton
177
- // primitives
178
- type Foo = 'a' | 'b';
179
-
180
- type Foo = string | string[];
181
-
182
- type Foo = `a-${number}` | `b-${number}`;
183
-
184
- // reference types
185
- interface Bar {}
186
- class Baz implements Bar {}
187
-
188
- type Foo = Bar | Baz;
189
- ```
190
-
191
- Examples of **incorrect** code for the `{ "allowAliases": "in-intersections" }` option:
192
-
193
- ```ts option='{ "allowAliases": "in-intersections" }' showPlaygroundButton
194
- // primitives
195
- type Foo = 'a';
196
-
197
- type Foo = 'a' | 'b';
198
-
199
- type Foo = string;
200
-
201
- type Foo = string | string[];
202
-
203
- type Foo = `a-${number}` | `b-${number}`;
204
-
205
- // reference types
206
- interface Bar {}
207
- class Baz implements Bar {}
208
-
209
- type Foo = Bar;
210
-
211
- type Foo = Bar | Baz;
212
- ```
213
-
214
- Examples of **correct** code for the `{ "allowAliases": "in-intersections" }` option:
215
-
216
- ```ts option='{ "allowAliases": "in-intersections" }' showPlaygroundButton
217
- // primitives
218
- type Foo = string & string[];
219
-
220
- type Foo = `a-${number}` & `b-${number}`;
221
-
222
- // reference types
223
- interface Bar {}
224
- class Baz implements Bar {}
225
-
226
- type Foo = Bar & Baz;
227
- ```
228
-
229
- Examples of **incorrect** code for the `{ "allowAliases": "in-unions-and-intersections" }` option:
230
-
231
- ```ts option='{ "allowAliases": "in-unions-and-intersections" }' showPlaygroundButton
232
- // primitives
233
- type Foo = 'a';
234
-
235
- type Foo = string;
236
-
237
- type Foo = `foo-${number}`;
238
-
239
- // reference types
240
- interface Bar {}
241
- class Baz implements Bar {}
242
-
243
- type Foo = Bar;
244
- ```
245
-
246
- Examples of **correct** code for the `{ "allowAliases": "in-unions-and-intersections" }` option:
247
-
248
- ```ts option='{ "allowAliases": "in-unions-and-intersections" }' showPlaygroundButton
249
- // primitives
250
- type Foo = 'a' | 'b';
251
-
252
- type Foo = string | string[];
253
-
254
- type Foo = string & string[];
255
-
256
- type Foo = `a-${number}` & `b-${number}`;
257
-
258
- type Foo = `a-${number}` | `b-${number}`;
259
-
260
- // reference types
261
- interface Bar {}
262
- class Baz implements Bar {}
263
-
264
- type Foo = Bar | Baz;
265
-
266
- type Foo = Bar & Baz;
267
- ```
268
-
269
- ### `allowCallbacks`
270
-
271
- {/* insert option description */}
272
-
273
- The setting accepts the following values:
274
-
275
- - `"always"` or `"never"` to active or deactivate the feature.
276
-
277
- Examples of **correct** code for the `{ "allowCallbacks": "always" }` option:
278
-
279
- ```ts option='{ "allowCallbacks": "always" }' showPlaygroundButton
280
- type Foo = () => void;
281
-
282
- type Foo = (name: string) => string;
283
-
284
- class Person {}
285
-
286
- type Foo = (name: string, age: number) => string | Person;
287
-
288
- type Foo = (name: string, age: number) => string & Person;
289
- ```
290
-
291
- ### `allowConditionalTypes`
292
-
293
- {/* insert option description */}
294
-
295
- Examples of **correct** code for the `{ "allowConditionalTypes": "always" }` option:
296
-
297
- ```ts option='{ "allowConditionalTypes": "always" }' showPlaygroundButton
298
- type Foo<T> = T extends number ? number : null;
299
- ```
300
-
301
- ### `allowConstructors`
302
-
303
- {/* insert option description */}
304
-
305
- The setting accepts the following values:
306
-
307
- - `"always"` or `"never"` to active or deactivate the feature.
308
-
309
- Examples of **correct** code for the `{ "allowConstructors": "always" }` option:
310
-
311
- ```ts option='{ "allowConstructors": "always" }' showPlaygroundButton
312
- type Foo = new () => void;
313
- ```
314
-
315
- ### `allowLiterals`
316
-
317
- {/* insert option description */}
318
-
319
- The setting accepts the following options:
320
-
321
- - `"always"` or `"never"` to active or deactivate the feature.
322
- - `"in-unions"`, allows literals in union statements, e.g. `type Foo = string | string[];`
323
- - `"in-intersections"`, allows literals in intersection statements, e.g. `type Foo = string & string[];`
324
- - `"in-unions-and-intersections"`, allows literals in union and/or intersection statements.
325
-
326
- Examples of **correct** code for the `{ "allowLiterals": "always" }` options:
327
-
328
- ```ts option='{ "allowLiterals": "always" }' showPlaygroundButton
329
- type Foo = {};
330
-
331
- type Foo = {
332
- name: string;
333
- age: number;
334
- };
335
-
336
- type Foo = {
337
- name: string;
338
- age: number;
339
- walk: (miles: number) => void;
340
- };
341
-
342
- type Foo = { name: string } | { age: number };
343
-
344
- type Foo = { name: string } & { age: number };
345
- ```
346
-
347
- Examples of **incorrect** code for the `{ "allowLiterals": "in-unions" }` option:
348
-
349
- ```ts option='{ "allowLiterals": "in-unions" }' showPlaygroundButton
350
- type Foo = {};
351
-
352
- type Foo = {
353
- name: string;
354
- age: number;
355
- };
356
-
357
- type Foo = {
358
- name: string;
359
- age: number;
360
- walk: (miles: number) => void;
361
- };
362
-
363
- type Foo = { name: string } & { age: number };
364
- ```
365
-
366
- Examples of **correct** code for the `{ "allowLiterals": "in-unions" }` option:
367
-
368
- ```ts option='{ "allowLiterals": "in-unions" }' showPlaygroundButton
369
- type Foo = { name: string } | { age: number };
370
- ```
371
-
372
- Examples of **incorrect** code for the `{ "allowLiterals": "in-intersections" }` option:
373
-
374
- ```ts option='{ "allowLiterals": "in-intersections" }' showPlaygroundButton
375
- type Foo = {};
376
-
377
- type Foo = {
378
- name: string;
379
- age: number;
380
- };
381
-
382
- type Foo = {
383
- name: string;
384
- age: number;
385
- walk: (miles: number) => void;
386
- };
387
-
388
- type Foo = { name: string } | { age: number };
389
- ```
390
-
391
- Examples of **correct** code for the `{ "allowLiterals": "in-intersections" }` option:
392
-
393
- ```ts option='{ "allowLiterals": "in-intersections" }' showPlaygroundButton
394
- type Foo = { name: string } & { age: number };
395
- ```
396
-
397
- Examples of **incorrect** code for the `{ "allowLiterals": "in-unions-and-intersections" }` option:
398
-
399
- ```ts option='{ "allowLiterals": "in-unions-and-intersections" }' showPlaygroundButton
400
- type Foo = {};
401
-
402
- type Foo = {
403
- name: string;
404
- age: number;
405
- };
406
-
407
- type Foo = {
408
- name: string;
409
- age: number;
410
- walk: (miles: number) => void;
411
- };
412
- ```
413
-
414
- Examples of **correct** code for the `{ "allowLiterals": "in-unions-and-intersections" }` option:
415
-
416
- ```ts option='{ "allowLiterals": "in-unions-and-intersections" }' showPlaygroundButton
417
- type Foo = { name: string } | { age: number };
418
-
419
- type Foo = { name: string } & { age: number };
420
- ```
421
-
422
- ### `allowMappedTypes`
423
-
424
- {/* insert option description */}
425
-
426
- The setting accepts the following values:
427
-
428
- - `"always"` or `"never"` to active or deactivate the feature.
429
- - `"in-unions"`, allows aliasing in union statements, e.g. `type Foo = string | string[];`
430
- - `"in-intersections"`, allows aliasing in intersection statements, e.g. `type Foo = string & string[];`
431
- - `"in-unions-and-intersections"`, allows aliasing in union and/or intersection statements.
432
-
433
- Examples of **correct** code for the `{ "allowMappedTypes": "always" }` options:
434
-
435
- ```ts option='{ "allowMappedTypes": "always" }' showPlaygroundButton
436
- type Foo<T> = { readonly [P in keyof T]: T[P] };
437
-
438
- type Foo<T> = { [P in keyof T]?: T[P] };
439
-
440
- type Foo<T, U> =
441
- | { readonly [P in keyof T]: T[P] }
442
- | { readonly [P in keyof U]: U[P] };
443
-
444
- type Foo<T, U> = { [P in keyof T]?: T[P] } | { [P in keyof U]?: U[P] };
445
-
446
- type Foo<T, U> = { readonly [P in keyof T]: T[P] } & {
447
- readonly [P in keyof U]: U[P];
448
- };
449
-
450
- type Foo<T, U> = { [P in keyof T]?: T[P] } & { [P in keyof U]?: U[P] };
451
- ```
452
-
453
- Examples of **incorrect** code for the `{ "allowMappedTypes": "in-unions" }` option:
454
-
455
- ```ts option='{ "allowMappedTypes": "in-unions" }' showPlaygroundButton
456
- type Foo<T> = { readonly [P in keyof T]: T[P] };
457
-
458
- type Foo<T> = { [P in keyof T]?: T[P] };
459
-
460
- type Foo<T, U> = { readonly [P in keyof T]: T[P] } & {
461
- readonly [P in keyof U]: U[P];
462
- };
463
-
464
- type Foo<T, U> = { [P in keyof T]?: T[P] } & { [P in keyof U]?: U[P] };
465
- ```
466
-
467
- Examples of **correct** code for the `{ "allowMappedTypes": "in-unions" }` option:
468
-
469
- ```ts option='{ "allowMappedTypes": "in-unions" }' showPlaygroundButton
470
- type Foo<T, U> =
471
- | { readonly [P in keyof T]: T[P] }
472
- | { readonly [P in keyof U]: U[P] };
473
-
474
- type Foo<T, U> = { [P in keyof T]?: T[P] } | { [P in keyof U]?: U[P] };
475
- ```
476
-
477
- Examples of **incorrect** code for the `{ "allowMappedTypes": "in-intersections" }` option:
478
-
479
- ```ts option='{ "allowMappedTypes": "in-intersections" }' showPlaygroundButton
480
- type Foo<T> = { readonly [P in keyof T]: T[P] };
481
-
482
- type Foo<T> = { [P in keyof T]?: T[P] };
483
-
484
- type Foo<T, U> =
485
- | { readonly [P in keyof T]: T[P] }
486
- | { readonly [P in keyof U]: U[P] };
487
-
488
- type Foo<T, U> = { [P in keyof T]?: T[P] } | { [P in keyof U]?: U[P] };
489
- ```
490
-
491
- Examples of **correct** code for the `{ "allowMappedTypes": "in-intersections" }` option:
492
-
493
- ```ts option='{ "allowMappedTypes": "in-intersections" }' showPlaygroundButton
494
- type Foo<T, U> = { readonly [P in keyof T]: T[P] } & {
495
- readonly [P in keyof U]: U[P];
496
- };
497
-
498
- type Foo<T, U> = { [P in keyof T]?: T[P] } & { [P in keyof U]?: U[P] };
499
- ```
500
-
501
- Examples of **incorrect** code for the `{ "allowMappedTypes": "in-unions-and-intersections" }` option:
502
-
503
- ```ts option='{ "allowMappedTypes": "in-unions-and-intersections" }' showPlaygroundButton
504
- type Foo<T> = { readonly [P in keyof T]: T[P] };
505
-
506
- type Foo<T> = { [P in keyof T]?: T[P] };
507
- ```
508
-
509
- Examples of **correct** code for the `{ "allowMappedTypes": "in-unions-and-intersections" }` option:
510
-
511
- ```ts option='{ "allowMappedTypes": "in-unions-and-intersections" }' showPlaygroundButton
512
- type Foo<T, U> =
513
- | { readonly [P in keyof T]: T[P] }
514
- | { readonly [P in keyof U]: U[P] };
515
-
516
- type Foo<T, U> = { [P in keyof T]?: T[P] } | { [P in keyof U]?: U[P] };
517
-
518
- type Foo<T, U> = { readonly [P in keyof T]: T[P] } & {
519
- readonly [P in keyof U]: U[P];
520
- };
521
-
522
- type Foo<T, U> = { [P in keyof T]?: T[P] } & { [P in keyof U]?: U[P] };
523
- ```
524
-
525
- ### `allowTupleTypes`
526
-
527
- {/* insert option description */}
528
-
529
- The setting accepts the following options:
530
-
531
- - `"always"` or `"never"` to active or deactivate the feature.
532
- - `"in-unions"`, allows tuples in union statements, e.g. `type Foo = [string] | [string, string];`
533
- - `"in-intersections"`, allows tuples in intersection statements, e.g. `type Foo = [string] & [string, string];`
534
- - `"in-unions-and-intersections"`, allows tuples in union and/or intersection statements.
535
-
536
- Examples of **correct** code for the `{ "allowTupleTypes": "always" }` options:
537
-
538
- ```ts option='{ "allowTupleTypes": "always" }' showPlaygroundButton
539
- type Foo = [number];
540
-
541
- type Foo = [number] | [number, number];
542
-
543
- type Foo = [number] & [number, number];
544
-
545
- type Foo = [number] | ([number, number] & [string, string]);
546
- ```
547
-
548
- Examples of **incorrect** code for the `{ "allowTupleTypes": "in-unions" }` option:
549
-
550
- ```ts option='{ "allowTupleTypes": "in-unions" }' showPlaygroundButton
551
- type Foo = [number];
552
-
553
- type Foo = [number] & [number, number];
554
-
555
- type Foo = [string] & [number];
556
- ```
557
-
558
- Examples of **correct** code for the `{ "allowTupleTypes": "in-unions" }` option:
559
-
560
- ```ts option='{ "allowTupleTypes": "in-unions" }' showPlaygroundButton
561
- type Foo = [number] | [number, number];
562
-
563
- type Foo = [string] | [number];
564
- ```
565
-
566
- Examples of **incorrect** code for the `{ "allowTupleTypes": "in-intersections" }` option:
567
-
568
- ```ts option='{ "allowTupleTypes": "in-intersections" }' showPlaygroundButton
569
- type Foo = [number];
570
-
571
- type Foo = [number] | [number, number];
572
-
573
- type Foo = [string] | [number];
574
- ```
575
-
576
- Examples of **correct** code for the `{ "allowTupleTypes": "in-intersections" }` option:
577
-
578
- ```ts option='{ "allowTupleTypes": "in-intersections" }' showPlaygroundButton
579
- type Foo = [number] & [number, number];
580
-
581
- type Foo = [string] & [number];
582
- ```
583
-
584
- Examples of **incorrect** code for the `{ "allowTupleTypes": "in-unions-and-intersections" }` option:
585
-
586
- ```ts option='{ "allowTupleTypes": "in-unions-and-intersections" }' showPlaygroundButton
587
- type Foo = [number];
588
-
589
- type Foo = [string];
590
- ```
591
-
592
- Examples of **correct** code for the `{ "allowTupleTypes": "in-unions-and-intersections" }` option:
593
-
594
- ```ts option='{ "allowTupleTypes": "in-unions-and-intersections" }' showPlaygroundButton
595
- type Foo = [number] & [number, number];
596
-
597
- type Foo = [string] | [number];
598
- ```
599
-
600
- ### `allowGenerics`
601
-
602
- {/* insert option description */}
603
-
604
- The setting accepts the following options:
605
-
606
- - `"always"` or `"never"` to active or deactivate the feature.
607
-
608
- Examples of **correct** code for the `{ "allowGenerics": "always" }` options:
609
-
610
- ```ts option='{ "allowGenerics": "always" }' showPlaygroundButton
611
- type Foo = Bar<string>;
612
-
613
- type Foo = Record<string, number>;
614
-
615
- type Foo = Readonly<Bar>;
616
-
617
- type Foo = Partial<Bar>;
618
-
619
- type Foo = Omit<Bar, 'a' | 'b'>;
620
- ```
621
-
622
- {/* Intentionally Omitted: When Not To Use It */}
623
-
624
- ## Further Reading
625
-
626
- - [Advanced Types](https://www.typescriptlang.org/docs/handbook/advanced-types.html)