UNPKG

1.8 kBTypeScriptView Raw
1/*
2We purposely don't generate types for our plugin because TL;DR:
31) there's no real reason that anyone should do a typed import of our rules,
42) it would require us to change our code so there aren't as many inferred types
5
6This type declaration exists as a hacky way to add a type to the export for our
7internal packages that require it.
8
9*** Long reason ***
10
11When you turn on declaration files, TS requires all types to be "fully resolvable"
12without changes to the code.
13All of our lint rules `export default createRule(...)`, which means they all
14implicitly reference the `TSESLint.Rule` type for the export.
15
16TS wants to transpile each rule file to this `.d.ts` file:
17
18```ts
19import type { TSESLint } from '@typescript-eslint/utils';
20declare const _default: TSESLint.RuleModule<TMessageIds, TOptions, TSESLint.RuleListener>;
21export default _default;
22```
23
24Because we don't import `TSESLint` in most files, it means that TS would have to
25insert a new import during the declaration emit to make this work.
26However TS wants to avoid adding new imports to the file because a new module
27could have type side-effects (like global augmentation) which could cause weird
28type side-effects in the decl file that wouldn't exist in source TS file.
29
30So TS errors on most of our rules with the following error:
31```
32The inferred type of 'default' cannot be named without a reference to
33'../../../../node_modules/@typescript-eslint/utils/src/ts-eslint/Rule'.
34This is likely not portable. A type annotation is necessary. ts(2742)
35```
36*/
37
38import type { RuleModule } from '@typescript-eslint/utils/ts-eslint';
39
40export type TypeScriptESLintRules = Record<
41 string,
42 RuleModule<string, unknown[]>
43>;
44declare const rules: TypeScriptESLintRules;
45// eslint-disable-next-line import/no-default-export
46export default rules;