@typescript-eslint/eslint-plugin 7.0.0-alpha.0 → 7.0.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 (484) hide show
  1. package/dist/configs/all.js +12 -40
  2. package/dist/configs/all.js.map +1 -1
  3. package/dist/configs/base.js +0 -6
  4. package/dist/configs/base.js.map +1 -1
  5. package/dist/configs/disable-type-checked.js +7 -1
  6. package/dist/configs/disable-type-checked.js.map +1 -1
  7. package/dist/configs/eslint-recommended-raw.js +40 -0
  8. package/dist/configs/eslint-recommended-raw.js.map +1 -0
  9. package/dist/configs/eslint-recommended.js +10 -27
  10. package/dist/configs/eslint-recommended.js.map +1 -1
  11. package/dist/configs/recommended-type-checked.js.map +1 -1
  12. package/dist/configs/recommended.js.map +1 -1
  13. package/dist/configs/strict-type-checked.js +4 -0
  14. package/dist/configs/strict-type-checked.js.map +1 -1
  15. package/dist/configs/strict.js.map +1 -1
  16. package/dist/configs/stylistic-type-checked.js.map +1 -1
  17. package/dist/configs/stylistic.js.map +1 -1
  18. package/dist/index.js +6 -0
  19. package/dist/index.js.map +1 -1
  20. package/dist/rules/adjacent-overload-signatures.js +31 -60
  21. package/dist/rules/adjacent-overload-signatures.js.map +1 -1
  22. package/dist/rules/array-type.js +7 -32
  23. package/dist/rules/array-type.js.map +1 -1
  24. package/dist/rules/await-thenable.js +15 -4
  25. package/dist/rules/await-thenable.js.map +1 -1
  26. package/dist/rules/ban-ts-comment.js +32 -34
  27. package/dist/rules/ban-ts-comment.js.map +1 -1
  28. package/dist/rules/ban-tslint-comment.js +5 -29
  29. package/dist/rules/ban-tslint-comment.js.map +1 -1
  30. package/dist/rules/ban-types.js +4 -27
  31. package/dist/rules/ban-types.js.map +1 -1
  32. package/dist/rules/block-spacing.js +11 -34
  33. package/dist/rules/block-spacing.js.map +1 -1
  34. package/dist/rules/brace-style.js +10 -9
  35. package/dist/rules/brace-style.js.map +1 -1
  36. package/dist/rules/class-literal-property-style.js +20 -31
  37. package/dist/rules/class-literal-property-style.js.map +1 -1
  38. package/dist/rules/class-methods-use-this.js +209 -0
  39. package/dist/rules/class-methods-use-this.js.map +1 -0
  40. package/dist/rules/comma-dangle.js +11 -31
  41. package/dist/rules/comma-dangle.js.map +1 -1
  42. package/dist/rules/comma-spacing.js +11 -12
  43. package/dist/rules/comma-spacing.js.map +1 -1
  44. package/dist/rules/consistent-generic-constructors.js +23 -25
  45. package/dist/rules/consistent-generic-constructors.js.map +1 -1
  46. package/dist/rules/consistent-indexed-object-style.js +10 -14
  47. package/dist/rules/consistent-indexed-object-style.js.map +1 -1
  48. package/dist/rules/consistent-type-assertions.js +36 -21
  49. package/dist/rules/consistent-type-assertions.js.map +1 -1
  50. package/dist/rules/consistent-type-definitions.js +14 -40
  51. package/dist/rules/consistent-type-definitions.js.map +1 -1
  52. package/dist/rules/consistent-type-exports.js +19 -39
  53. package/dist/rules/consistent-type-exports.js.map +1 -1
  54. package/dist/rules/consistent-type-imports.js +88 -101
  55. package/dist/rules/consistent-type-imports.js.map +1 -1
  56. package/dist/rules/default-param-last.js +1 -1
  57. package/dist/rules/default-param-last.js.map +1 -1
  58. package/dist/rules/dot-notation.js.map +1 -1
  59. package/dist/rules/enum-utils/shared.js +57 -6
  60. package/dist/rules/enum-utils/shared.js.map +1 -1
  61. package/dist/rules/explicit-function-return-type.js +6 -31
  62. package/dist/rules/explicit-function-return-type.js.map +1 -1
  63. package/dist/rules/explicit-member-accessibility.js +8 -32
  64. package/dist/rules/explicit-member-accessibility.js.map +1 -1
  65. package/dist/rules/explicit-module-boundary-types.js +11 -35
  66. package/dist/rules/explicit-module-boundary-types.js.map +1 -1
  67. package/dist/rules/func-call-spacing.js +12 -35
  68. package/dist/rules/func-call-spacing.js.map +1 -1
  69. package/dist/rules/indent.js +18 -42
  70. package/dist/rules/indent.js.map +1 -1
  71. package/dist/rules/index.js +16 -0
  72. package/dist/rules/index.js.map +1 -1
  73. package/dist/rules/init-declarations.js.map +1 -1
  74. package/dist/rules/key-spacing.js +27 -59
  75. package/dist/rules/key-spacing.js.map +1 -1
  76. package/dist/rules/keyword-spacing.js +9 -31
  77. package/dist/rules/keyword-spacing.js.map +1 -1
  78. package/dist/rules/lines-around-comment.js +24 -48
  79. package/dist/rules/lines-around-comment.js.map +1 -1
  80. package/dist/rules/lines-between-class-members.js +5 -26
  81. package/dist/rules/lines-between-class-members.js.map +1 -1
  82. package/dist/rules/max-params.js +67 -0
  83. package/dist/rules/max-params.js.map +1 -0
  84. package/dist/rules/member-delimiter-style.js +12 -34
  85. package/dist/rules/member-delimiter-style.js.map +1 -1
  86. package/dist/rules/member-ordering.js +48 -40
  87. package/dist/rules/member-ordering.js.map +1 -1
  88. package/dist/rules/method-signature-style.js +14 -38
  89. package/dist/rules/method-signature-style.js.map +1 -1
  90. package/dist/rules/naming-convention-utils/enums.js +13 -5
  91. package/dist/rules/naming-convention-utils/enums.js.map +1 -1
  92. package/dist/rules/naming-convention-utils/format.js.map +1 -1
  93. package/dist/rules/naming-convention-utils/parse-options.js +3 -25
  94. package/dist/rules/naming-convention-utils/parse-options.js.map +1 -1
  95. package/dist/rules/naming-convention-utils/schema.js +8 -33
  96. package/dist/rules/naming-convention-utils/schema.js.map +1 -1
  97. package/dist/rules/naming-convention-utils/validator.js +3 -26
  98. package/dist/rules/naming-convention-utils/validator.js.map +1 -1
  99. package/dist/rules/naming-convention.js +59 -60
  100. package/dist/rules/naming-convention.js.map +1 -1
  101. package/dist/rules/no-array-constructor.js +4 -27
  102. package/dist/rules/no-array-constructor.js.map +1 -1
  103. package/dist/rules/no-array-delete.js +81 -0
  104. package/dist/rules/no-array-delete.js.map +1 -0
  105. package/dist/rules/no-base-to-string.js +7 -7
  106. package/dist/rules/no-base-to-string.js.map +1 -1
  107. package/dist/rules/no-confusing-non-null-assertion.js +5 -30
  108. package/dist/rules/no-confusing-non-null-assertion.js.map +1 -1
  109. package/dist/rules/no-confusing-void-expression.js +33 -20
  110. package/dist/rules/no-confusing-void-expression.js.map +1 -1
  111. package/dist/rules/no-dupe-class-members.js +3 -37
  112. package/dist/rules/no-dupe-class-members.js.map +1 -1
  113. package/dist/rules/no-duplicate-enum-values.js +2 -25
  114. package/dist/rules/no-duplicate-enum-values.js.map +1 -1
  115. package/dist/rules/no-duplicate-type-constituents.js +7 -31
  116. package/dist/rules/no-duplicate-type-constituents.js.map +1 -1
  117. package/dist/rules/no-dynamic-delete.js +4 -5
  118. package/dist/rules/no-dynamic-delete.js.map +1 -1
  119. package/dist/rules/no-empty-function.js +9 -32
  120. package/dist/rules/no-empty-function.js.map +1 -1
  121. package/dist/rules/no-empty-interface.js +8 -33
  122. package/dist/rules/no-empty-interface.js.map +1 -1
  123. package/dist/rules/no-explicit-any.js +12 -36
  124. package/dist/rules/no-explicit-any.js.map +1 -1
  125. package/dist/rules/no-extra-non-null-assertion.js +2 -25
  126. package/dist/rules/no-extra-non-null-assertion.js.map +1 -1
  127. package/dist/rules/no-extra-parens.js +47 -86
  128. package/dist/rules/no-extra-parens.js.map +1 -1
  129. package/dist/rules/no-extra-semi.js +5 -37
  130. package/dist/rules/no-extra-semi.js.map +1 -1
  131. package/dist/rules/no-extraneous-class.js +2 -25
  132. package/dist/rules/no-extraneous-class.js.map +1 -1
  133. package/dist/rules/no-floating-promises.js +137 -54
  134. package/dist/rules/no-floating-promises.js.map +1 -1
  135. package/dist/rules/no-for-in-array.js +6 -6
  136. package/dist/rules/no-for-in-array.js.map +1 -1
  137. package/dist/rules/no-implied-eval.js +7 -7
  138. package/dist/rules/no-implied-eval.js.map +1 -1
  139. package/dist/rules/no-import-type-side-effects.js +4 -28
  140. package/dist/rules/no-import-type-side-effects.js.map +1 -1
  141. package/dist/rules/no-inferrable-types.js +12 -36
  142. package/dist/rules/no-inferrable-types.js.map +1 -1
  143. package/dist/rules/no-invalid-this.js +2 -10
  144. package/dist/rules/no-invalid-this.js.map +1 -1
  145. package/dist/rules/no-invalid-void-type.js +6 -30
  146. package/dist/rules/no-invalid-void-type.js.map +1 -1
  147. package/dist/rules/no-loop-func.js +4 -28
  148. package/dist/rules/no-loop-func.js.map +1 -1
  149. package/dist/rules/no-loss-of-precision.js +5 -32
  150. package/dist/rules/no-loss-of-precision.js.map +1 -1
  151. package/dist/rules/no-magic-numbers.js +5 -28
  152. package/dist/rules/no-magic-numbers.js.map +1 -1
  153. package/dist/rules/no-meaningless-void-operator.js +4 -5
  154. package/dist/rules/no-meaningless-void-operator.js.map +1 -1
  155. package/dist/rules/no-misused-new.js +2 -25
  156. package/dist/rules/no-misused-new.js.map +1 -1
  157. package/dist/rules/no-misused-promises.js +5 -5
  158. package/dist/rules/no-misused-promises.js.map +1 -1
  159. package/dist/rules/no-mixed-enums.js +6 -7
  160. package/dist/rules/no-mixed-enums.js.map +1 -1
  161. package/dist/rules/no-namespace.js +4 -29
  162. package/dist/rules/no-namespace.js.map +1 -1
  163. package/dist/rules/no-non-null-asserted-nullish-coalescing.js +5 -29
  164. package/dist/rules/no-non-null-asserted-nullish-coalescing.js.map +1 -1
  165. package/dist/rules/no-non-null-asserted-optional-chain.js +2 -25
  166. package/dist/rules/no-non-null-asserted-optional-chain.js.map +1 -1
  167. package/dist/rules/no-non-null-assertion.js +20 -46
  168. package/dist/rules/no-non-null-assertion.js.map +1 -1
  169. package/dist/rules/no-redeclare.js +7 -31
  170. package/dist/rules/no-redeclare.js.map +1 -1
  171. package/dist/rules/no-redundant-type-constituents.js +12 -13
  172. package/dist/rules/no-redundant-type-constituents.js.map +1 -1
  173. package/dist/rules/no-require-imports.js +30 -4
  174. package/dist/rules/no-require-imports.js.map +1 -1
  175. package/dist/rules/no-restricted-imports.js +100 -77
  176. package/dist/rules/no-restricted-imports.js.map +1 -1
  177. package/dist/rules/no-shadow.js +30 -56
  178. package/dist/rules/no-shadow.js.map +1 -1
  179. package/dist/rules/no-this-alias.js +2 -25
  180. package/dist/rules/no-this-alias.js.map +1 -1
  181. package/dist/rules/no-throw-literal.js +6 -36
  182. package/dist/rules/no-throw-literal.js.map +1 -1
  183. package/dist/rules/no-type-alias.js +2 -25
  184. package/dist/rules/no-type-alias.js.map +1 -1
  185. package/dist/rules/no-unnecessary-boolean-literal-compare.js +6 -7
  186. package/dist/rules/no-unnecessary-boolean-literal-compare.js.map +1 -1
  187. package/dist/rules/no-unnecessary-condition.js +62 -22
  188. package/dist/rules/no-unnecessary-condition.js.map +1 -1
  189. package/dist/rules/no-unnecessary-qualifier.js +8 -7
  190. package/dist/rules/no-unnecessary-qualifier.js.map +1 -1
  191. package/dist/rules/no-unnecessary-type-arguments.js +5 -6
  192. package/dist/rules/no-unnecessary-type-arguments.js.map +1 -1
  193. package/dist/rules/no-unnecessary-type-assertion.js +37 -32
  194. package/dist/rules/no-unnecessary-type-assertion.js.map +1 -1
  195. package/dist/rules/no-unnecessary-type-constraint.js +18 -6
  196. package/dist/rules/no-unnecessary-type-constraint.js.map +1 -1
  197. package/dist/rules/no-unsafe-argument.js +11 -11
  198. package/dist/rules/no-unsafe-argument.js.map +1 -1
  199. package/dist/rules/no-unsafe-assignment.js +15 -17
  200. package/dist/rules/no-unsafe-assignment.js.map +1 -1
  201. package/dist/rules/no-unsafe-call.js +5 -6
  202. package/dist/rules/no-unsafe-call.js.map +1 -1
  203. package/dist/rules/no-unsafe-declaration-merging.js +4 -27
  204. package/dist/rules/no-unsafe-declaration-merging.js.map +1 -1
  205. package/dist/rules/no-unsafe-enum-comparison.js +94 -45
  206. package/dist/rules/no-unsafe-enum-comparison.js.map +1 -1
  207. package/dist/rules/no-unsafe-member-access.js +8 -10
  208. package/dist/rules/no-unsafe-member-access.js.map +1 -1
  209. package/dist/rules/no-unsafe-return.js +15 -15
  210. package/dist/rules/no-unsafe-return.js.map +1 -1
  211. package/dist/rules/no-unsafe-unary-minus.js +68 -0
  212. package/dist/rules/no-unsafe-unary-minus.js.map +1 -0
  213. package/dist/rules/no-unused-expressions.js +10 -25
  214. package/dist/rules/no-unused-expressions.js.map +1 -1
  215. package/dist/rules/no-unused-vars.js +37 -79
  216. package/dist/rules/no-unused-vars.js.map +1 -1
  217. package/dist/rules/no-use-before-define.js +8 -35
  218. package/dist/rules/no-use-before-define.js.map +1 -1
  219. package/dist/rules/no-useless-constructor.js +3 -27
  220. package/dist/rules/no-useless-constructor.js.map +1 -1
  221. package/dist/rules/no-useless-empty-export.js +18 -36
  222. package/dist/rules/no-useless-empty-export.js.map +1 -1
  223. package/dist/rules/no-useless-template-literals.js +138 -0
  224. package/dist/rules/no-useless-template-literals.js.map +1 -0
  225. package/dist/rules/no-var-requires.js +36 -39
  226. package/dist/rules/no-var-requires.js.map +1 -1
  227. package/dist/rules/non-nullable-type-assertion-style.js +9 -8
  228. package/dist/rules/non-nullable-type-assertion-style.js.map +1 -1
  229. package/dist/rules/object-curly-spacing.js +20 -19
  230. package/dist/rules/object-curly-spacing.js.map +1 -1
  231. package/dist/rules/padding-line-between-statements.js +28 -54
  232. package/dist/rules/padding-line-between-statements.js.map +1 -1
  233. package/dist/rules/parameter-properties.js +4 -29
  234. package/dist/rules/parameter-properties.js.map +1 -1
  235. package/dist/rules/prefer-as-const.js +2 -25
  236. package/dist/rules/prefer-as-const.js.map +1 -1
  237. package/dist/rules/prefer-destructuring.js +200 -0
  238. package/dist/rules/prefer-destructuring.js.map +1 -0
  239. package/dist/rules/prefer-enum-initializers.js +3 -27
  240. package/dist/rules/prefer-enum-initializers.js.map +1 -1
  241. package/dist/rules/prefer-find.js +237 -0
  242. package/dist/rules/prefer-find.js.map +1 -0
  243. package/dist/rules/prefer-for-of.js +7 -32
  244. package/dist/rules/prefer-for-of.js.map +1 -1
  245. package/dist/rules/prefer-function-type.js +9 -32
  246. package/dist/rules/prefer-function-type.js.map +1 -1
  247. package/dist/rules/prefer-includes.js +2 -2
  248. package/dist/rules/prefer-includes.js.map +1 -1
  249. package/dist/rules/prefer-literal-enum-member.js.map +1 -1
  250. package/dist/rules/prefer-namespace-keyword.js +4 -28
  251. package/dist/rules/prefer-namespace-keyword.js.map +1 -1
  252. package/dist/rules/prefer-nullish-coalescing.js +42 -30
  253. package/dist/rules/prefer-nullish-coalescing.js.map +1 -1
  254. package/dist/rules/prefer-optional-chain-utils/analyzeChain.js +20 -22
  255. package/dist/rules/prefer-optional-chain-utils/analyzeChain.js.map +1 -1
  256. package/dist/rules/prefer-optional-chain-utils/compareNodes.js.map +1 -1
  257. package/dist/rules/prefer-optional-chain-utils/gatherLogicalOperands.js +8 -10
  258. package/dist/rules/prefer-optional-chain-utils/gatherLogicalOperands.js.map +1 -1
  259. package/dist/rules/prefer-optional-chain.js +9 -11
  260. package/dist/rules/prefer-optional-chain.js.map +1 -1
  261. package/dist/rules/prefer-promise-reject-errors.js +108 -0
  262. package/dist/rules/prefer-promise-reject-errors.js.map +1 -0
  263. package/dist/rules/prefer-readonly-parameter-types.js +8 -31
  264. package/dist/rules/prefer-readonly-parameter-types.js.map +1 -1
  265. package/dist/rules/prefer-readonly.js +61 -17
  266. package/dist/rules/prefer-readonly.js.map +1 -1
  267. package/dist/rules/prefer-reduce-type-parameter.js +6 -32
  268. package/dist/rules/prefer-reduce-type-parameter.js.map +1 -1
  269. package/dist/rules/prefer-regexp-exec.js +8 -10
  270. package/dist/rules/prefer-regexp-exec.js.map +1 -1
  271. package/dist/rules/prefer-return-this-type.js +2 -4
  272. package/dist/rules/prefer-return-this-type.js.map +1 -1
  273. package/dist/rules/prefer-string-starts-ends-with.js +44 -26
  274. package/dist/rules/prefer-string-starts-ends-with.js.map +1 -1
  275. package/dist/rules/prefer-ts-expect-error.js +3 -27
  276. package/dist/rules/prefer-ts-expect-error.js.map +1 -1
  277. package/dist/rules/promise-function-async.js +11 -12
  278. package/dist/rules/promise-function-async.js.map +1 -1
  279. package/dist/rules/quotes.js +5 -26
  280. package/dist/rules/quotes.js.map +1 -1
  281. package/dist/rules/require-array-sort-compare.js +17 -39
  282. package/dist/rules/require-array-sort-compare.js.map +1 -1
  283. package/dist/rules/require-await.js +22 -50
  284. package/dist/rules/require-await.js.map +1 -1
  285. package/dist/rules/restrict-plus-operands.js +7 -7
  286. package/dist/rules/restrict-plus-operands.js.map +1 -1
  287. package/dist/rules/restrict-template-expressions.js +11 -11
  288. package/dist/rules/restrict-template-expressions.js.map +1 -1
  289. package/dist/rules/return-await.js +12 -15
  290. package/dist/rules/return-await.js.map +1 -1
  291. package/dist/rules/semi.js +4 -25
  292. package/dist/rules/semi.js.map +1 -1
  293. package/dist/rules/sort-type-constituents.js +5 -30
  294. package/dist/rules/sort-type-constituents.js.map +1 -1
  295. package/dist/rules/space-before-blocks.js +8 -31
  296. package/dist/rules/space-before-blocks.js.map +1 -1
  297. package/dist/rules/space-before-function-paren.js +14 -39
  298. package/dist/rules/space-before-function-paren.js.map +1 -1
  299. package/dist/rules/space-infix-ops.js +18 -40
  300. package/dist/rules/space-infix-ops.js.map +1 -1
  301. package/dist/rules/strict-boolean-expressions.js +94 -85
  302. package/dist/rules/strict-boolean-expressions.js.map +1 -1
  303. package/dist/rules/switch-exhaustiveness-check.js +153 -50
  304. package/dist/rules/switch-exhaustiveness-check.js.map +1 -1
  305. package/dist/rules/triple-slash-reference.js +3 -27
  306. package/dist/rules/triple-slash-reference.js.map +1 -1
  307. package/dist/rules/type-annotation-spacing.js +17 -46
  308. package/dist/rules/type-annotation-spacing.js.map +1 -1
  309. package/dist/rules/typedef.js +6 -30
  310. package/dist/rules/typedef.js.map +1 -1
  311. package/dist/rules/unbound-method.js +21 -61
  312. package/dist/rules/unbound-method.js.map +1 -1
  313. package/dist/rules/unified-signatures.js +12 -37
  314. package/dist/rules/unified-signatures.js.map +1 -1
  315. package/dist/util/astUtils.js +4 -4
  316. package/dist/util/astUtils.js.map +1 -1
  317. package/dist/util/collectUnusedVariables.js +8 -9
  318. package/dist/util/collectUnusedVariables.js.map +1 -1
  319. package/dist/util/explicitReturnTypeUtils.js +43 -34
  320. package/dist/util/explicitReturnTypeUtils.js.map +1 -1
  321. package/dist/util/getESLintCoreRule.js +3 -31
  322. package/dist/util/getESLintCoreRule.js.map +1 -1
  323. package/dist/util/getFunctionHeadLoc.js +146 -36
  324. package/dist/util/getFunctionHeadLoc.js.map +1 -1
  325. package/dist/util/getOperatorPrecedence.js +1 -0
  326. package/dist/util/getOperatorPrecedence.js.map +1 -1
  327. package/dist/util/getStaticStringValue.js +46 -0
  328. package/dist/util/getStaticStringValue.js.map +1 -0
  329. package/dist/util/getStringLength.js.map +1 -1
  330. package/dist/util/getThisExpression.js +1 -1
  331. package/dist/util/getThisExpression.js.map +1 -1
  332. package/dist/util/getWrappedCode.js +8 -0
  333. package/dist/util/getWrappedCode.js.map +1 -0
  334. package/dist/util/getWrappingFixer.js +19 -5
  335. package/dist/util/getWrappingFixer.js.map +1 -1
  336. package/dist/util/index.js +1 -0
  337. package/dist/util/index.js.map +1 -1
  338. package/dist/util/isNodeEqual.js.map +1 -1
  339. package/dist/util/misc.js +5 -7
  340. package/dist/util/misc.js.map +1 -1
  341. package/dist/util/objectIterators.js.map +1 -1
  342. package/docs/rules/README.md +44 -7
  343. package/docs/rules/TEMPLATE.md +5 -1
  344. package/docs/rules/adjacent-overload-signatures.md +7 -1
  345. package/docs/rules/array-type.md +14 -6
  346. package/docs/rules/await-thenable.md +3 -1
  347. package/docs/rules/ban-ts-comment.md +12 -9
  348. package/docs/rules/ban-tslint-comment.md +3 -3
  349. package/docs/rules/ban-types.md +11 -62
  350. package/docs/rules/block-spacing.md +0 -2
  351. package/docs/rules/brace-style.md +0 -2
  352. package/docs/rules/camelcase.md +5 -2
  353. package/docs/rules/class-literal-property-style.md +5 -14
  354. package/docs/rules/class-methods-use-this.md +96 -0
  355. package/docs/rules/comma-dangle.md +0 -2
  356. package/docs/rules/comma-spacing.md +0 -2
  357. package/docs/rules/consistent-generic-constructors.md +7 -4
  358. package/docs/rules/consistent-indexed-object-style.md +12 -12
  359. package/docs/rules/consistent-type-assertions.md +27 -22
  360. package/docs/rules/consistent-type-definitions.md +12 -13
  361. package/docs/rules/consistent-type-exports.md +9 -4
  362. package/docs/rules/consistent-type-imports.md +9 -6
  363. package/docs/rules/default-param-last.md +16 -6
  364. package/docs/rules/dot-notation.md +10 -5
  365. package/docs/rules/explicit-function-return-type.md +31 -30
  366. package/docs/rules/explicit-member-accessibility.md +49 -36
  367. package/docs/rules/explicit-module-boundary-types.md +30 -31
  368. package/docs/rules/func-call-spacing.md +0 -2
  369. package/docs/rules/indent.md +0 -2
  370. package/docs/rules/init-declarations.md +0 -2
  371. package/docs/rules/key-spacing.md +1 -3
  372. package/docs/rules/keyword-spacing.md +1 -3
  373. package/docs/rules/lines-around-comment.md +0 -2
  374. package/docs/rules/lines-between-class-members.md +2 -10
  375. package/docs/rules/max-params.md +10 -0
  376. package/docs/rules/member-delimiter-style.md +4 -1
  377. package/docs/rules/member-ordering.md +278 -200
  378. package/docs/rules/method-signature-style.md +7 -4
  379. package/docs/rules/naming-convention.md +31 -16
  380. package/docs/rules/no-array-constructor.md +0 -6
  381. package/docs/rules/no-array-delete.md +40 -0
  382. package/docs/rules/no-base-to-string.md +2 -2
  383. package/docs/rules/no-confusing-void-expression.md +3 -3
  384. package/docs/rules/no-dupe-class-members.md +3 -1
  385. package/docs/rules/no-duplicate-enum-values.md +8 -0
  386. package/docs/rules/no-duplicate-imports.md +5 -2
  387. package/docs/rules/no-duplicate-type-constituents.md +7 -2
  388. package/docs/rules/no-dynamic-delete.md +1 -1
  389. package/docs/rules/no-empty-function.md +13 -9
  390. package/docs/rules/no-empty-interface.md +2 -13
  391. package/docs/rules/no-explicit-any.md +28 -34
  392. package/docs/rules/no-extra-non-null-assertion.md +2 -0
  393. package/docs/rules/no-extra-parens.md +0 -2
  394. package/docs/rules/no-extra-semi.md +2 -2
  395. package/docs/rules/no-extraneous-class.md +10 -9
  396. package/docs/rules/no-floating-promises.md +24 -6
  397. package/docs/rules/no-for-in-array.md +13 -8
  398. package/docs/rules/no-implied-eval.md +2 -1
  399. package/docs/rules/no-import-type-side-effects.md +1 -2
  400. package/docs/rules/no-inferrable-types.md +4 -4
  401. package/docs/rules/no-invalid-this.md +3 -1
  402. package/docs/rules/no-invalid-void-type.md +5 -6
  403. package/docs/rules/no-loop-func.md +0 -2
  404. package/docs/rules/no-loss-of-precision.md +0 -2
  405. package/docs/rules/no-magic-numbers.md +14 -26
  406. package/docs/rules/no-meaningless-void-operator.md +6 -0
  407. package/docs/rules/no-misused-new.md +2 -1
  408. package/docs/rules/no-misused-promises.md +14 -13
  409. package/docs/rules/no-namespace.md +9 -7
  410. package/docs/rules/no-non-null-asserted-nullish-coalescing.md +5 -0
  411. package/docs/rules/no-non-null-asserted-optional-chain.md +5 -0
  412. package/docs/rules/no-non-null-assertion.md +2 -2
  413. package/docs/rules/no-parameter-properties.md +12 -0
  414. package/docs/rules/no-redeclare.md +5 -3
  415. package/docs/rules/no-redundant-type-constituents.md +14 -0
  416. package/docs/rules/no-require-imports.md +24 -1
  417. package/docs/rules/no-restricted-imports.md +24 -16
  418. package/docs/rules/no-shadow.md +15 -11
  419. package/docs/rules/no-this-alias.md +73 -3
  420. package/docs/rules/no-throw-literal.md +9 -11
  421. package/docs/rules/no-type-alias.md +55 -48
  422. package/docs/rules/no-unnecessary-boolean-literal-compare.md +5 -5
  423. package/docs/rules/no-unnecessary-condition.md +18 -2
  424. package/docs/rules/no-unnecessary-qualifier.md +1 -1
  425. package/docs/rules/no-unnecessary-type-arguments.md +7 -1
  426. package/docs/rules/no-unnecessary-type-assertion.md +2 -2
  427. package/docs/rules/no-unnecessary-type-constraint.md +1 -1
  428. package/docs/rules/no-unsafe-argument.md +12 -2
  429. package/docs/rules/no-unsafe-assignment.md +11 -1
  430. package/docs/rules/no-unsafe-call.md +10 -0
  431. package/docs/rules/no-unsafe-declaration-merging.md +5 -0
  432. package/docs/rules/no-unsafe-enum-comparison.md +15 -10
  433. package/docs/rules/no-unsafe-member-access.md +11 -1
  434. package/docs/rules/no-unsafe-return.md +11 -1
  435. package/docs/rules/no-unsafe-unary-minus.md +52 -0
  436. package/docs/rules/no-unused-expressions.md +0 -2
  437. package/docs/rules/no-unused-vars.md +17 -2
  438. package/docs/rules/no-use-before-define.md +4 -14
  439. package/docs/rules/no-useless-constructor.md +0 -2
  440. package/docs/rules/no-useless-empty-export.md +4 -0
  441. package/docs/rules/no-useless-template-literals.md +57 -0
  442. package/docs/rules/no-var-requires.md +24 -1
  443. package/docs/rules/non-nullable-type-assertion-style.md +1 -1
  444. package/docs/rules/object-curly-spacing.md +0 -2
  445. package/docs/rules/padding-line-between-statements.md +3 -5
  446. package/docs/rules/parameter-properties.md +22 -19
  447. package/docs/rules/prefer-as-const.md +4 -1
  448. package/docs/rules/prefer-destructuring.md +91 -0
  449. package/docs/rules/prefer-enum-initializers.md +1 -1
  450. package/docs/rules/prefer-find.md +39 -0
  451. package/docs/rules/prefer-for-of.md +3 -5
  452. package/docs/rules/prefer-function-type.md +1 -1
  453. package/docs/rules/prefer-includes.md +1 -3
  454. package/docs/rules/prefer-literal-enum-member.md +6 -4
  455. package/docs/rules/prefer-namespace-keyword.md +1 -1
  456. package/docs/rules/prefer-nullish-coalescing.md +27 -15
  457. package/docs/rules/prefer-optional-chain.md +18 -17
  458. package/docs/rules/prefer-promise-reject-errors.md +50 -0
  459. package/docs/rules/prefer-readonly-parameter-types.md +58 -32
  460. package/docs/rules/prefer-readonly.md +19 -4
  461. package/docs/rules/prefer-reduce-type-parameter.md +3 -1
  462. package/docs/rules/prefer-string-starts-ends-with.md +2 -1
  463. package/docs/rules/prefer-ts-expect-error.md +1 -0
  464. package/docs/rules/promise-function-async.md +73 -0
  465. package/docs/rules/quotes.md +0 -2
  466. package/docs/rules/require-array-sort-compare.md +7 -7
  467. package/docs/rules/require-await.md +2 -2
  468. package/docs/rules/restrict-plus-operands.md +16 -16
  469. package/docs/rules/restrict-template-expressions.md +11 -7
  470. package/docs/rules/return-await.md +8 -8
  471. package/docs/rules/semi.md +0 -4
  472. package/docs/rules/sort-type-constituents.md +62 -0
  473. package/docs/rules/space-before-blocks.md +5 -4
  474. package/docs/rules/space-before-function-paren.md +0 -2
  475. package/docs/rules/strict-boolean-expressions.md +7 -0
  476. package/docs/rules/switch-exhaustiveness-check.md +127 -8
  477. package/docs/rules/triple-slash-reference.md +76 -25
  478. package/docs/rules/type-annotation-spacing.md +8 -8
  479. package/docs/rules/typedef.md +19 -19
  480. package/docs/rules/unbound-method.md +4 -2
  481. package/docs/rules/unified-signatures.md +11 -2
  482. package/index.d.ts +6 -2
  483. package/package.json +32 -24
  484. package/rules.d.ts +46 -0
@@ -28,9 +28,32 @@ import { lib2 } from 'lib2';
28
28
  import * as lib3 from 'lib3';
29
29
  ```
30
30
 
31
+ ## Options
32
+
33
+ ### `allow`
34
+
35
+ A array of strings. 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.
36
+
37
+ With `{allow: ['/package\\.json$']}`:
38
+
39
+ <!--tabs-->
40
+
41
+ ### ❌ Incorrect
42
+
43
+ ```ts
44
+ console.log(require('../data.json').version);
45
+ ```
46
+
47
+ ### ✅ Correct
48
+
49
+ ```ts
50
+ console.log(require('../package.json').version);
51
+ ```
52
+
31
53
  ## When Not To Use It
32
54
 
33
- If you don't care about using newer module syntax, then you will not need this rule.
55
+ If your project frequently uses older CommonJS `require`s, then this rule might not be applicable to you.
56
+ If only a subset of your project uses `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.
34
57
 
35
58
  ## Related To
36
59
 
@@ -6,9 +6,7 @@ description: 'Disallow specified modules when loaded by `import`.'
6
6
  >
7
7
  > See **https://typescript-eslint.io/rules/no-restricted-imports** for documentation.
8
8
 
9
- ## Examples
10
-
11
- This rule extends the base [`eslint/no-restricted-imports`](https://eslint.org/docs/rules/no-restricted-imports) rule.
9
+ This rule extends the base [`eslint/no-restricted-imports`](https://eslint.org/docs/rules/no-restricted-imports) rule. It adds support for the type import (`import type X from "..."`, `import { type X } from "..."`) and `import x = require("...")` syntaxes.
12
10
 
13
11
  ## Options
14
12
 
@@ -21,17 +19,27 @@ This rule adds the following options:
21
19
  You can specify this option for a specific path or pattern as follows:
22
20
 
23
21
  ```jsonc
24
- "@typescript-eslint/no-restricted-imports": ["error", {
25
- "paths": [{
26
- "name": "import-foo",
27
- "message": "Please use import-bar instead.",
28
- "allowTypeImports": true
29
- }, {
30
- "name": "import-baz",
31
- "message": "Please use import-quux instead.",
32
- "allowTypeImports": true
33
- }]
34
- }]
22
+ {
23
+ "rules": {
24
+ "@typescript-eslint/no-restricted-imports": [
25
+ "error",
26
+ {
27
+ "paths": [
28
+ {
29
+ "name": "import-foo",
30
+ "message": "Please use import-bar instead.",
31
+ "allowTypeImports": true,
32
+ },
33
+ {
34
+ "name": "import-baz",
35
+ "message": "Please use import-quux instead.",
36
+ "allowTypeImports": true,
37
+ },
38
+ ],
39
+ },
40
+ ],
41
+ },
42
+ }
35
43
  ```
36
44
 
37
45
  When set to `true`, the rule will allow [Type-Only Imports](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-8.html#type-only-imports-and-export).
@@ -42,7 +50,7 @@ Examples of code with the above config:
42
50
 
43
51
  #### ❌ Incorrect
44
52
 
45
- ```ts
53
+ ```ts option='{"paths":[{"name":"import-foo","message":"Please use import-bar instead.","allowTypeImports":true},{"name":"import-baz","message":"Please use import-quux instead.","allowTypeImports":true}]}'
46
54
  import foo from 'import-foo';
47
55
  export { Foo } from 'import-foo';
48
56
 
@@ -52,7 +60,7 @@ export { Baz } from 'import-baz';
52
60
 
53
61
  #### ✅ Correct
54
62
 
55
- ```ts
63
+ ```ts option='{"paths":[{"name":"import-foo","message":"Please use import-bar instead.","allowTypeImports":true},{"name":"import-baz","message":"Please use import-quux instead.","allowTypeImports":true}]}'
56
64
  import { foo } from 'other-module';
57
65
 
58
66
  import type foo from 'import-foo';
@@ -6,8 +6,6 @@ description: 'Disallow variable declarations from shadowing variables declared i
6
6
  >
7
7
  > See **https://typescript-eslint.io/rules/no-shadow** for documentation.
8
8
 
9
- ## Examples
10
-
11
9
  This rule extends the base [`eslint/no-shadow`](https://eslint.org/docs/rules/no-shadow) rule.
12
10
  It adds support for TypeScript's `this` parameters and global augmentation, and adds options for TypeScript features.
13
11
 
@@ -30,25 +28,31 @@ const defaultOptions: Options = {
30
28
 
31
29
  ### `ignoreTypeValueShadow`
32
30
 
33
- When set to `true`, the rule will ignore the case when you name a type the same as a variable.
34
-
35
- TypeScript allows types and variables to shadow one-another. This is generally safe because you cannot use variables in type locations without a `typeof` operator, so there's little risk of confusion.
31
+ When set to `true`, the rule will ignore the case when you name a type the same as a variable. This is generally safe because you cannot use variables in type locations without a `typeof` operator, so there's little risk of confusion.
36
32
 
37
33
  Examples of **correct** code with `{ ignoreTypeValueShadow: true }`:
38
34
 
39
- ```ts
35
+ ```ts option='{ "ignoreTypeValueShadow": true }' showPlaygroundButton
40
36
  type Foo = number;
41
- const Foo = 1;
42
-
43
37
  interface Bar {
44
38
  prop: number;
45
39
  }
46
- const Bar = 'test';
40
+
41
+ function f() {
42
+ const Foo = 1;
43
+ const Bar = 'test';
44
+ }
47
45
  ```
48
46
 
47
+ :::note
48
+
49
+ _Shadowing_ specifically refers to two identical identifiers that are in different, nested scopes. This is different from _redeclaration_, which is when two identical identifiers are in the same scope. Redeclaration is covered by the [`no-redeclare`](./no-redeclare.md) rule instead.
50
+
51
+ :::
52
+
49
53
  ### `ignoreFunctionTypeParameterNameValueShadow`
50
54
 
51
- When set to `true`, the rule will ignore the case when you name a function type argument the same as a variable.
55
+ When set to `true`, the rule will ignore the case when you name a parameter in a function type the same as a variable.
52
56
 
53
57
  Each of a function type's arguments creates a value variable within the scope of the function type. This is done so that you can reference the type later using the `typeof` operator:
54
58
 
@@ -74,7 +78,7 @@ If you do not use the `typeof` operator in a function type return type position,
74
78
 
75
79
  Examples of **correct** code with `{ ignoreFunctionTypeParameterNameValueShadow: true }`:
76
80
 
77
- ```ts
81
+ ```ts option='{ "ignoreFunctionTypeParameterNameValueShadow": true }' showPlaygroundButton
78
82
  const test = 1;
79
83
  type Func = (test: string) => typeof test;
80
84
  ```
@@ -15,7 +15,7 @@ or not managing scope well.
15
15
 
16
16
  ### ❌ Incorrect
17
17
 
18
- ```js
18
+ ```ts
19
19
  const self = this;
20
20
 
21
21
  setTimeout(function () {
@@ -25,7 +25,7 @@ setTimeout(function () {
25
25
 
26
26
  ### ✅ Correct
27
27
 
28
- ```js
28
+ ```ts
29
29
  setTimeout(() => {
30
30
  this.doWork();
31
31
  });
@@ -33,6 +33,76 @@ setTimeout(() => {
33
33
 
34
34
  ## Options
35
35
 
36
+ ### `allowDestructuring`
37
+
38
+ It can sometimes be useful to destructure properties from a class instance, such as retrieving multiple properties from the instance in one of its methods.
39
+ `allowDestructuring` allows those destructures and is `true` by default.
40
+ You can explicitly disallow them by setting `allowDestructuring` to `false`.
41
+
42
+ Examples of code for the `{ "allowDestructuring": false }` option:
43
+
44
+ <!--tabs-->
45
+
46
+ #### ❌ Incorrect
47
+
48
+ ```ts option='{ "allowDestructuring": false }'
49
+ class ComponentLike {
50
+ props: unknown;
51
+ state: unknown;
52
+
53
+ render() {
54
+ const { props, state } = this;
55
+
56
+ console.log(props);
57
+ console.log(state);
58
+ }
59
+ }
60
+ ```
61
+
62
+ #### ✅ Correct
63
+
64
+ ```ts option='{ "allowDestructuring": false }'
65
+ class ComponentLike {
66
+ props: unknown;
67
+ state: unknown;
68
+
69
+ render() {
70
+ console.log(this.props);
71
+ console.log(this.state);
72
+ }
73
+ }
74
+ ```
75
+
76
+ ### `allowedNames`
77
+
78
+ `no-this-alias` can alternately be used to allow only a specific list of names as `this` aliases.
79
+ We recommend against this except as a transitory step towards fixing all rule violations.
80
+
81
+ Examples of code for the `{ "allowedNames": ["self"] }` option:
82
+
83
+ <!--tabs-->
84
+
85
+ #### ❌ Incorrect
86
+
87
+ ```ts option='{ "allowedNames": ["self"] }'
88
+ class Example {
89
+ method() {
90
+ const that = this;
91
+ }
92
+ }
93
+ ```
94
+
95
+ #### ✅ Correct
96
+
97
+ ```ts option='{ "allowedNames": ["self"] }'
98
+ class Example {
99
+ method() {
100
+ const self = this;
101
+ }
102
+ }
103
+ ```
104
+
36
105
  ## When Not To Use It
37
106
 
38
- If you need to assign `this` to variables, you shouldn’t use this rule.
107
+ If your project is structured in a way that it needs to assign `this` to variables, this rule is likely not for you.
108
+ If only a subset of your project assigns `this` to variables 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.
@@ -20,8 +20,6 @@ This rule is aimed at maintaining consistency when throwing exception by disallo
20
20
  ### ❌ Incorrect
21
21
 
22
22
  ```ts
23
- /*eslint @typescript-eslint/no-throw-literal: "error"*/
24
-
25
23
  throw 'error';
26
24
 
27
25
  throw 0;
@@ -53,19 +51,17 @@ throw foo.bar;
53
51
  ### ✅ Correct
54
52
 
55
53
  ```ts
56
- /*eslint @typescript-eslint/no-throw-literal: "error"*/
57
-
58
54
  throw new Error();
59
55
 
60
- throw new Error("error");
56
+ throw new Error('error');
61
57
 
62
- const e = new Error("error");
58
+ const e = new Error('error');
63
59
  throw e;
64
60
 
65
61
  try {
66
- throw new Error("error");
62
+ throw new Error('error');
67
63
  } catch (e) {
68
- throw e;
64
+ throw e;
69
65
  }
70
66
 
71
67
  const err = new Error();
@@ -77,13 +73,13 @@ function err() {
77
73
  throw err();
78
74
 
79
75
  const foo = {
80
- bar: new Error();
81
- }
76
+ bar: new Error(),
77
+ };
82
78
  throw foo.bar;
83
79
 
84
80
  class CustomError extends Error {
85
81
  // ...
86
- };
82
+ }
87
83
  throw new CustomError();
88
84
  ```
89
85
 
@@ -109,3 +105,5 @@ const defaultOptions: Options = {
109
105
  allowThrowingUnknown: false,
110
106
  };
111
107
  ```
108
+
109
+ <!-- Intentionally omitted: When Not To Use It -->
@@ -27,15 +27,23 @@ In TypeScript, type aliases serve three purposes:
27
27
  ```ts
28
28
  // this...
29
29
  type Person = {
30
- firstName: string,
31
- lastName: string,
32
- age: number
30
+ firstName: string;
31
+ lastName: string;
32
+ age: number;
33
33
  };
34
34
 
35
- function addPerson(person : Person) { ... }
35
+ function addPerson(person: Person) {
36
+ // ...
37
+ }
36
38
 
37
39
  // is easier to read than this...
38
- function addPerson(person : { firstName: string, lastName: string, age: number}) { ... }
40
+ function addPerson(person: {
41
+ firstName: string;
42
+ lastName: string;
43
+ age: number;
44
+ }) {
45
+ // ...
46
+ }
39
47
  ```
40
48
 
41
49
  - Act sort of like an interface, providing a set of methods and properties that must exist
@@ -43,16 +51,18 @@ function addPerson(person : { firstName: string, lastName: string, age: number})
43
51
 
44
52
  ```ts
45
53
  type Person = {
46
- firstName: string,
47
- lastName: string,
48
- age: number,
49
- walk: () => void,
50
- talk: () => void
54
+ firstName: string;
55
+ lastName: string;
56
+ age: number;
57
+ walk: () => void;
58
+ talk: () => void;
51
59
  };
52
60
 
53
61
  // you know person will have 3 properties and 2 methods,
54
62
  // because the structure has already been defined.
55
- var person : Person = { ... }
63
+ var person: Person = {
64
+ // ...
65
+ };
56
66
 
57
67
  // so we can be sure that this will work
58
68
  person.walk();
@@ -112,7 +122,7 @@ The setting accepts the following values:
112
122
 
113
123
  Examples of **correct** code for the `{ "allowAliases": "always" }` options:
114
124
 
115
- ```ts
125
+ ```ts option='{ "allowAliases": "always" }' showPlaygroundButton
116
126
  // primitives
117
127
  type Foo = 'a';
118
128
 
@@ -139,7 +149,7 @@ type Foo = Bar & Baz;
139
149
 
140
150
  Examples of **incorrect** code for the `{ "allowAliases": "in-unions" }` option:
141
151
 
142
- ```ts
152
+ ```ts option='{ "allowAliases": "in-unions" }' showPlaygroundButton
143
153
  // primitives
144
154
  type Foo = 'a';
145
155
 
@@ -160,7 +170,7 @@ type Foo = Bar & Baz;
160
170
 
161
171
  Examples of **correct** code for the `{ "allowAliases": "in-unions" }` option:
162
172
 
163
- ```ts
173
+ ```ts option='{ "allowAliases": "in-unions" }' showPlaygroundButton
164
174
  // primitives
165
175
  type Foo = 'a' | 'b';
166
176
 
@@ -177,7 +187,7 @@ type Foo = Bar | Baz;
177
187
 
178
188
  Examples of **incorrect** code for the `{ "allowAliases": "in-intersections" }` option:
179
189
 
180
- ```ts
190
+ ```ts option='{ "allowAliases": "in-intersections" }' showPlaygroundButton
181
191
  // primitives
182
192
  type Foo = 'a';
183
193
 
@@ -200,7 +210,7 @@ type Foo = Bar | Baz;
200
210
 
201
211
  Examples of **correct** code for the `{ "allowAliases": "in-intersections" }` option:
202
212
 
203
- ```ts
213
+ ```ts option='{ "allowAliases": "in-intersections" }' showPlaygroundButton
204
214
  // primitives
205
215
  type Foo = string & string[];
206
216
 
@@ -215,7 +225,7 @@ type Foo = Bar & Baz;
215
225
 
216
226
  Examples of **incorrect** code for the `{ "allowAliases": "in-unions-and-intersections" }` option:
217
227
 
218
- ```ts
228
+ ```ts option='{ "allowAliases": "in-unions-and-intersections" }' showPlaygroundButton
219
229
  // primitives
220
230
  type Foo = 'a';
221
231
 
@@ -232,7 +242,7 @@ type Foo = Bar;
232
242
 
233
243
  Examples of **correct** code for the `{ "allowAliases": "in-unions-and-intersections" }` option:
234
244
 
235
- ```ts
245
+ ```ts option='{ "allowAliases": "in-unions-and-intersections" }' showPlaygroundButton
236
246
  // primitives
237
247
  type Foo = 'a' | 'b';
238
248
 
@@ -263,7 +273,7 @@ The setting accepts the following values:
263
273
 
264
274
  Examples of **correct** code for the `{ "allowCallbacks": "always" }` option:
265
275
 
266
- ```ts
276
+ ```ts option='{ "allowCallbacks": "always" }' showPlaygroundButton
267
277
  type Foo = () => void;
268
278
 
269
279
  type Foo = (name: string) => string;
@@ -281,7 +291,7 @@ This applies to conditional types.
281
291
 
282
292
  Examples of **correct** code for the `{ "allowConditionalTypes": "always" }` option:
283
293
 
284
- ```ts
294
+ ```ts option='{ "allowConditionalTypes": "always" }' showPlaygroundButton
285
295
  type Foo<T> = T extends number ? number : null;
286
296
  ```
287
297
 
@@ -295,7 +305,7 @@ The setting accepts the following values:
295
305
 
296
306
  Examples of **correct** code for the `{ "allowConstructors": "always" }` option:
297
307
 
298
- ```ts
308
+ ```ts option='{ "allowConstructors": "always" }' showPlaygroundButton
299
309
  type Foo = new () => void;
300
310
  ```
301
311
 
@@ -312,7 +322,7 @@ The setting accepts the following options:
312
322
 
313
323
  Examples of **correct** code for the `{ "allowLiterals": "always" }` options:
314
324
 
315
- ```ts
325
+ ```ts option='{ "allowLiterals": "always" }' showPlaygroundButton
316
326
  type Foo = {};
317
327
 
318
328
  type Foo = {
@@ -333,7 +343,7 @@ type Foo = { name: string } & { age: number };
333
343
 
334
344
  Examples of **incorrect** code for the `{ "allowLiterals": "in-unions" }` option:
335
345
 
336
- ```ts
346
+ ```ts option='{ "allowLiterals": "in-unions" }' showPlaygroundButton
337
347
  type Foo = {};
338
348
 
339
349
  type Foo = {
@@ -352,13 +362,13 @@ type Foo = { name: string } & { age: number };
352
362
 
353
363
  Examples of **correct** code for the `{ "allowLiterals": "in-unions" }` option:
354
364
 
355
- ```ts
365
+ ```ts option='{ "allowLiterals": "in-unions" }' showPlaygroundButton
356
366
  type Foo = { name: string } | { age: number };
357
367
  ```
358
368
 
359
369
  Examples of **incorrect** code for the `{ "allowLiterals": "in-intersections" }` option:
360
370
 
361
- ```ts
371
+ ```ts option='{ "allowLiterals": "in-intersections" }' showPlaygroundButton
362
372
  type Foo = {};
363
373
 
364
374
  type Foo = {
@@ -377,13 +387,13 @@ type Foo = { name: string } | { age: number };
377
387
 
378
388
  Examples of **correct** code for the `{ "allowLiterals": "in-intersections" }` option:
379
389
 
380
- ```ts
390
+ ```ts option='{ "allowLiterals": "in-intersections" }' showPlaygroundButton
381
391
  type Foo = { name: string } & { age: number };
382
392
  ```
383
393
 
384
394
  Examples of **incorrect** code for the `{ "allowLiterals": "in-unions-and-intersections" }` option:
385
395
 
386
- ```ts
396
+ ```ts option='{ "allowLiterals": "in-unions-and-intersections" }' showPlaygroundButton
387
397
  type Foo = {};
388
398
 
389
399
  type Foo = {
@@ -400,7 +410,7 @@ type Foo = {
400
410
 
401
411
  Examples of **correct** code for the `{ "allowLiterals": "in-unions-and-intersections" }` option:
402
412
 
403
- ```ts
413
+ ```ts option='{ "allowLiterals": "in-unions-and-intersections" }' showPlaygroundButton
404
414
  type Foo = { name: string } | { age: number };
405
415
 
406
416
  type Foo = { name: string } & { age: number };
@@ -419,7 +429,7 @@ The setting accepts the following values:
419
429
 
420
430
  Examples of **correct** code for the `{ "allowMappedTypes": "always" }` options:
421
431
 
422
- ```ts
432
+ ```ts option='{ "allowMappedTypes": "always" }' showPlaygroundButton
423
433
  type Foo<T> = { readonly [P in keyof T]: T[P] };
424
434
 
425
435
  type Foo<T> = { [P in keyof T]?: T[P] };
@@ -439,7 +449,7 @@ type Foo<T, U> = { [P in keyof T]?: T[P] } & { [P in keyof U]?: U[P] };
439
449
 
440
450
  Examples of **incorrect** code for the `{ "allowMappedTypes": "in-unions" }` option:
441
451
 
442
- ```ts
452
+ ```ts option='{ "allowMappedTypes": "in-unions" }' showPlaygroundButton
443
453
  type Foo<T> = { readonly [P in keyof T]: T[P] };
444
454
 
445
455
  type Foo<T> = { [P in keyof T]?: T[P] };
@@ -453,7 +463,7 @@ type Foo<T, U> = { [P in keyof T]?: T[P] } & { [P in keyof U]?: U[P] };
453
463
 
454
464
  Examples of **correct** code for the `{ "allowMappedTypes": "in-unions" }` option:
455
465
 
456
- ```ts
466
+ ```ts option='{ "allowMappedTypes": "in-unions" }' showPlaygroundButton
457
467
  type Foo<T, U> =
458
468
  | { readonly [P in keyof T]: T[P] }
459
469
  | { readonly [P in keyof U]: U[P] };
@@ -463,7 +473,7 @@ type Foo<T, U> = { [P in keyof T]?: T[P] } | { [P in keyof U]?: U[P] };
463
473
 
464
474
  Examples of **incorrect** code for the `{ "allowMappedTypes": "in-intersections" }` option:
465
475
 
466
- ```ts
476
+ ```ts option='{ "allowMappedTypes": "in-intersections" }' showPlaygroundButton
467
477
  type Foo<T> = { readonly [P in keyof T]: T[P] };
468
478
 
469
479
  type Foo<T> = { [P in keyof T]?: T[P] };
@@ -477,7 +487,7 @@ type Foo<T, U> = { [P in keyof T]?: T[P] } | { [P in keyof U]?: U[P] };
477
487
 
478
488
  Examples of **correct** code for the `{ "allowMappedTypes": "in-intersections" }` option:
479
489
 
480
- ```ts
490
+ ```ts option='{ "allowMappedTypes": "in-intersections" }' showPlaygroundButton
481
491
  type Foo<T, U> = { readonly [P in keyof T]: T[P] } & {
482
492
  readonly [P in keyof U]: U[P];
483
493
  };
@@ -487,7 +497,7 @@ type Foo<T, U> = { [P in keyof T]?: T[P] } & { [P in keyof U]?: U[P] };
487
497
 
488
498
  Examples of **incorrect** code for the `{ "allowMappedTypes": "in-unions-and-intersections" }` option:
489
499
 
490
- ```ts
500
+ ```ts option='{ "allowMappedTypes": "in-unions-and-intersections" }' showPlaygroundButton
491
501
  type Foo<T> = { readonly [P in keyof T]: T[P] };
492
502
 
493
503
  type Foo<T> = { [P in keyof T]?: T[P] };
@@ -495,7 +505,7 @@ type Foo<T> = { [P in keyof T]?: T[P] };
495
505
 
496
506
  Examples of **correct** code for the `{ "allowMappedTypes": "in-unions-and-intersections" }` option:
497
507
 
498
- ```ts
508
+ ```ts option='{ "allowMappedTypes": "in-unions-and-intersections" }' showPlaygroundButton
499
509
  type Foo<T, U> =
500
510
  | { readonly [P in keyof T]: T[P] }
501
511
  | { readonly [P in keyof U]: U[P] };
@@ -522,7 +532,7 @@ The setting accepts the following options:
522
532
 
523
533
  Examples of **correct** code for the `{ "allowTupleTypes": "always" }` options:
524
534
 
525
- ```ts
535
+ ```ts option='{ "allowTupleTypes": "always" }' showPlaygroundButton
526
536
  type Foo = [number];
527
537
 
528
538
  type Foo = [number] | [number, number];
@@ -534,7 +544,7 @@ type Foo = [number] | ([number, number] & [string, string]);
534
544
 
535
545
  Examples of **incorrect** code for the `{ "allowTupleTypes": "in-unions" }` option:
536
546
 
537
- ```ts
547
+ ```ts option='{ "allowTupleTypes": "in-unions" }' showPlaygroundButton
538
548
  type Foo = [number];
539
549
 
540
550
  type Foo = [number] & [number, number];
@@ -544,7 +554,7 @@ type Foo = [string] & [number];
544
554
 
545
555
  Examples of **correct** code for the `{ "allowTupleTypes": "in-unions" }` option:
546
556
 
547
- ```ts
557
+ ```ts option='{ "allowTupleTypes": "in-unions" }' showPlaygroundButton
548
558
  type Foo = [number] | [number, number];
549
559
 
550
560
  type Foo = [string] | [number];
@@ -552,7 +562,7 @@ type Foo = [string] | [number];
552
562
 
553
563
  Examples of **incorrect** code for the `{ "allowTupleTypes": "in-intersections" }` option:
554
564
 
555
- ```ts
565
+ ```ts option='{ "allowTupleTypes": "in-intersections" }' showPlaygroundButton
556
566
  type Foo = [number];
557
567
 
558
568
  type Foo = [number] | [number, number];
@@ -562,7 +572,7 @@ type Foo = [string] | [number];
562
572
 
563
573
  Examples of **correct** code for the `{ "allowTupleTypes": "in-intersections" }` option:
564
574
 
565
- ```ts
575
+ ```ts option='{ "allowTupleTypes": "in-intersections" }' showPlaygroundButton
566
576
  type Foo = [number] & [number, number];
567
577
 
568
578
  type Foo = [string] & [number];
@@ -570,15 +580,15 @@ type Foo = [string] & [number];
570
580
 
571
581
  Examples of **incorrect** code for the `{ "allowTupleTypes": "in-unions-and-intersections" }` option:
572
582
 
573
- ```ts
583
+ ```ts option='{ "allowTupleTypes": "in-unions-and-intersections" }' showPlaygroundButton
574
584
  type Foo = [number];
575
585
 
576
586
  type Foo = [string];
577
587
  ```
578
588
 
579
- Examples of **correct** code for the `{ "allowLiterals": "in-unions-and-intersections" }` option:
589
+ Examples of **correct** code for the `{ "allowTupleTypes": "in-unions-and-intersections" }` option:
580
590
 
581
- ```ts
591
+ ```ts option='{ "allowTupleTypes": "in-unions-and-intersections" }' showPlaygroundButton
582
592
  type Foo = [number] & [number, number];
583
593
 
584
594
  type Foo = [string] | [number];
@@ -594,7 +604,7 @@ The setting accepts the following options:
594
604
 
595
605
  Examples of **correct** code for the `{ "allowGenerics": "always" }` options:
596
606
 
597
- ```ts
607
+ ```ts option='{ "allowGenerics": "always" }' showPlaygroundButton
598
608
  type Foo = Bar<string>;
599
609
 
600
610
  type Foo = Record<string, number>;
@@ -606,10 +616,7 @@ type Foo = Partial<Bar>;
606
616
  type Foo = Omit<Bar, 'a' | 'b'>;
607
617
  ```
608
618
 
609
- ## When Not To Use It
610
-
611
- When you can't express some shape with an interface or you need to use a union, tuple type,
612
- callback, etc. that would cause the code to be unreadable or impractical.
619
+ <!-- Intentionally Omitted: When Not To Use It -->
613
620
 
614
621
  ## Further Reading
615
622