eslint-plugin-typefest 1.0.3 → 1.0.5
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/README.md +18 -2
- package/dist/_internal/rule-catalog.d.ts.map +1 -1
- package/dist/_internal/rule-catalog.js +9 -0
- package/dist/_internal/rule-catalog.js.map +1 -1
- package/dist/_internal/rules-registry.d.ts.map +1 -1
- package/dist/_internal/rules-registry.js +18 -0
- package/dist/_internal/rules-registry.js.map +1 -1
- package/dist/plugin.cjs +866 -36
- package/dist/plugin.cjs.map +4 -4
- package/dist/rules/prefer-type-fest-and-all.d.ts +13 -0
- package/dist/rules/prefer-type-fest-and-all.d.ts.map +1 -0
- package/dist/rules/prefer-type-fest-and-all.js +105 -0
- package/dist/rules/prefer-type-fest-and-all.js.map +1 -0
- package/dist/rules/prefer-type-fest-array-length.d.ts +13 -0
- package/dist/rules/prefer-type-fest-array-length.d.ts.map +1 -0
- package/dist/rules/prefer-type-fest-array-length.js +77 -0
- package/dist/rules/prefer-type-fest-array-length.js.map +1 -0
- package/dist/rules/prefer-type-fest-conditional-pick-deep.d.ts +13 -0
- package/dist/rules/prefer-type-fest-conditional-pick-deep.d.ts.map +1 -0
- package/dist/rules/prefer-type-fest-conditional-pick-deep.js +75 -0
- package/dist/rules/prefer-type-fest-conditional-pick-deep.js.map +1 -0
- package/dist/rules/prefer-type-fest-less-than-or-equal.d.ts +13 -0
- package/dist/rules/prefer-type-fest-less-than-or-equal.d.ts.map +1 -0
- package/dist/rules/prefer-type-fest-less-than-or-equal.js +153 -0
- package/dist/rules/prefer-type-fest-less-than-or-equal.js.map +1 -0
- package/dist/rules/prefer-type-fest-less-than.d.ts +13 -0
- package/dist/rules/prefer-type-fest-less-than.d.ts.map +1 -0
- package/dist/rules/prefer-type-fest-less-than.js +154 -0
- package/dist/rules/prefer-type-fest-less-than.js.map +1 -0
- package/dist/rules/prefer-type-fest-optional.d.ts +13 -0
- package/dist/rules/prefer-type-fest-optional.d.ts.map +1 -0
- package/dist/rules/prefer-type-fest-optional.js +130 -0
- package/dist/rules/prefer-type-fest-optional.js.map +1 -0
- package/dist/rules/prefer-type-fest-or-all.d.ts +13 -0
- package/dist/rules/prefer-type-fest-or-all.d.ts.map +1 -0
- package/dist/rules/prefer-type-fest-or-all.js +105 -0
- package/dist/rules/prefer-type-fest-or-all.js.map +1 -0
- package/dist/rules/prefer-type-fest-union-member.d.ts +13 -0
- package/dist/rules/prefer-type-fest-union-member.d.ts.map +1 -0
- package/dist/rules/prefer-type-fest-union-member.js +159 -0
- package/dist/rules/prefer-type-fest-union-member.js.map +1 -0
- package/dist/rules/prefer-type-fest-union-to-tuple.d.ts +13 -0
- package/dist/rules/prefer-type-fest-union-to-tuple.d.ts.map +1 -0
- package/dist/rules/prefer-type-fest-union-to-tuple.js +75 -0
- package/dist/rules/prefer-type-fest-union-to-tuple.js.map +1 -0
- package/docs/rules/prefer-type-fest-and-all.md +111 -0
- package/docs/rules/prefer-type-fest-array-length.md +109 -0
- package/docs/rules/prefer-type-fest-conditional-pick-deep.md +112 -0
- package/docs/rules/prefer-type-fest-less-than-or-equal.md +111 -0
- package/docs/rules/prefer-type-fest-less-than.md +111 -0
- package/docs/rules/prefer-type-fest-optional.md +104 -0
- package/docs/rules/prefer-type-fest-or-all.md +111 -0
- package/docs/rules/prefer-type-fest-union-member.md +119 -0
- package/docs/rules/prefer-type-fest-union-to-tuple.md +108 -0
- package/docs/rules/presets/all.md +9 -0
- package/docs/rules/presets/index.md +87 -78
- package/docs/rules/presets/recommended-type-checked.md +74 -65
- package/docs/rules/presets/recommended.md +8 -0
- package/docs/rules/presets/strict.md +9 -0
- package/docs/rules/presets/type-fest-types.md +8 -0
- package/package.json +32 -25
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
# prefer-type-fest-optional
|
|
2
|
+
|
|
3
|
+
Require TypeFest [`Optional<Value>`](https://github.com/sindresorhus/type-fest/blob/main/source/optional.d.ts) over `Exclude<T, null> | undefined` and `NonNullable<T> | undefined` patterns.
|
|
4
|
+
|
|
5
|
+
## Targeted pattern scope
|
|
6
|
+
|
|
7
|
+
This rule targets optional-value patterns that normalize `null` away and add `undefined`.
|
|
8
|
+
|
|
9
|
+
## What this rule reports
|
|
10
|
+
|
|
11
|
+
- `Exclude<T, null> | undefined`
|
|
12
|
+
- `Exclude<T, null | undefined> | undefined`
|
|
13
|
+
- `NonNullable<T> | undefined`
|
|
14
|
+
|
|
15
|
+
## Why this rule exists
|
|
16
|
+
|
|
17
|
+
`Optional<Value>` is the canonical TypeFest helper for “value or `undefined`, but never `null`”. Using it makes the intent obvious and standardizes on the new TypeFest utility.
|
|
18
|
+
|
|
19
|
+
## ❌ Incorrect
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
type MaybeName = Exclude<string | null, null> | undefined;
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## ✅ Correct
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
import type { Optional } from "type-fest";
|
|
29
|
+
|
|
30
|
+
type MaybeName = Optional<string | null>;
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Behavior and migration notes
|
|
34
|
+
|
|
35
|
+
- This rule only targets explicit null-stripping plus `undefined` patterns.
|
|
36
|
+
- It does not report plain `T | undefined` unions.
|
|
37
|
+
- It will not autofix when `Optional` is shadowed in the local type scope.
|
|
38
|
+
|
|
39
|
+
## Additional examples
|
|
40
|
+
|
|
41
|
+
### ❌ Incorrect — Additional example
|
|
42
|
+
|
|
43
|
+
```ts
|
|
44
|
+
type MaybeRegion = NonNullable<string | null> | undefined;
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### ✅ Correct — Additional example
|
|
48
|
+
|
|
49
|
+
```ts
|
|
50
|
+
import type { Optional } from "type-fest";
|
|
51
|
+
|
|
52
|
+
type MaybeRegion = Optional<string | null>;
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### ✅ Correct — Non-targeted usage
|
|
56
|
+
|
|
57
|
+
```ts
|
|
58
|
+
type MaybeRegion = string | undefined;
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## ESLint flat config example
|
|
62
|
+
|
|
63
|
+
```ts
|
|
64
|
+
import typefest from "eslint-plugin-typefest";
|
|
65
|
+
|
|
66
|
+
export default [
|
|
67
|
+
{
|
|
68
|
+
plugins: { typefest },
|
|
69
|
+
rules: {
|
|
70
|
+
"typefest/prefer-type-fest-optional": "error",
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
];
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## When not to use it
|
|
77
|
+
|
|
78
|
+
Disable this rule if your codebase intentionally prefers native utility combinations over the TypeFest helper name.
|
|
79
|
+
|
|
80
|
+
## Package documentation
|
|
81
|
+
|
|
82
|
+
TypeFest package documentation:
|
|
83
|
+
|
|
84
|
+
Source file: [`source/optional.d.ts`](https://github.com/sindresorhus/type-fest/blob/main/source/optional.d.ts)
|
|
85
|
+
|
|
86
|
+
```ts
|
|
87
|
+
/**
|
|
88
|
+
Create a type that represents either the value or `undefined`, while stripping `null` from the type.
|
|
89
|
+
*/
|
|
90
|
+
export type Optional<Value> = Exclude<Value, null> | undefined;
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
> **Rule catalog ID:** R079
|
|
94
|
+
|
|
95
|
+
## Further reading
|
|
96
|
+
|
|
97
|
+
- [`type-fest` README](https://github.com/sindresorhus/type-fest)
|
|
98
|
+
- [`type-fest` npm documentation](https://www.npmjs.com/package/type-fest)
|
|
99
|
+
- [TypeScript Handbook: Utility Types](https://www.typescriptlang.org/docs/handbook/utility-types.html)
|
|
100
|
+
|
|
101
|
+
## Adoption resources
|
|
102
|
+
|
|
103
|
+
- [Rule adoption checklist](./guides/adoption-checklist.md)
|
|
104
|
+
- [Rollout and fix safety](./guides/rollout-and-fix-safety.md)
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
# prefer-type-fest-or-all
|
|
2
|
+
|
|
3
|
+
Require TypeFest [`OrAll<TTuple>`](https://github.com/sindresorhus/type-fest/blob/main/source/or-all.d.ts) over `SomeExtend<TTuple, true>` boolean-tuple checks.
|
|
4
|
+
|
|
5
|
+
## Targeted pattern scope
|
|
6
|
+
|
|
7
|
+
This rule targets direct and namespace-qualified references to `SomeExtend<TTuple, true>` imported from `type-fest`.
|
|
8
|
+
|
|
9
|
+
## What this rule reports
|
|
10
|
+
|
|
11
|
+
- `SomeExtend<TTuple, true>` when it is being used as a boolean-tuple disjunction check.
|
|
12
|
+
|
|
13
|
+
## Why this rule exists
|
|
14
|
+
|
|
15
|
+
`OrAll` is the dedicated TypeFest helper for checking whether any boolean tuple member is `true`. It is shorter, clearer, and matches the new canonical TypeFest naming.
|
|
16
|
+
|
|
17
|
+
## ❌ Incorrect
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import type { SomeExtend } from "type-fest";
|
|
21
|
+
|
|
22
|
+
type AnyFlagsTrue = SomeExtend<[false, false, true], true>;
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## ✅ Correct
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
import type { OrAll } from "type-fest";
|
|
29
|
+
|
|
30
|
+
type AnyFlagsTrue = OrAll<[false, false, true]>;
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Behavior and migration notes
|
|
34
|
+
|
|
35
|
+
- This rule only targets `SomeExtend<TTuple, true>`.
|
|
36
|
+
- It does not report `SomeExtend<TTuple, SomeOtherType>` usages.
|
|
37
|
+
- Namespace-qualified `type-fest` references are reported too.
|
|
38
|
+
|
|
39
|
+
## Additional examples
|
|
40
|
+
|
|
41
|
+
### ❌ Incorrect — Additional example
|
|
42
|
+
|
|
43
|
+
```ts
|
|
44
|
+
import type * as TypeFest from "type-fest";
|
|
45
|
+
|
|
46
|
+
type Ready = TypeFest.SomeExtend<[false, false, true], true>;
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### ✅ Correct — Additional example
|
|
50
|
+
|
|
51
|
+
```ts
|
|
52
|
+
import type { OrAll } from "type-fest";
|
|
53
|
+
|
|
54
|
+
type Ready = OrAll<[false, false, true]>;
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### ✅ Correct — Non-targeted usage
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
import type { SomeExtend } from "type-fest";
|
|
61
|
+
|
|
62
|
+
type AnyStrings = SomeExtend<[1, "x", true], string>;
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## ESLint flat config example
|
|
66
|
+
|
|
67
|
+
```ts
|
|
68
|
+
import typefest from "eslint-plugin-typefest";
|
|
69
|
+
|
|
70
|
+
export default [
|
|
71
|
+
{
|
|
72
|
+
plugins: { typefest },
|
|
73
|
+
rules: {
|
|
74
|
+
"typefest/prefer-type-fest-or-all": "error",
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
];
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## When not to use it
|
|
81
|
+
|
|
82
|
+
Disable this rule if your codebase intentionally prefers the more general `SomeExtend<TTuple, true>` spelling for boolean tuple checks.
|
|
83
|
+
|
|
84
|
+
## Package documentation
|
|
85
|
+
|
|
86
|
+
TypeFest package documentation:
|
|
87
|
+
|
|
88
|
+
Source file: [`source/or-all.d.ts`](https://github.com/sindresorhus/type-fest/blob/main/source/or-all.d.ts)
|
|
89
|
+
|
|
90
|
+
```ts
|
|
91
|
+
/**
|
|
92
|
+
Returns a boolean for whether any of the given elements is `true`.
|
|
93
|
+
|
|
94
|
+
Use-cases:
|
|
95
|
+
- Check if at least one condition in a list of booleans is met.
|
|
96
|
+
*/
|
|
97
|
+
export type OrAll<T extends readonly boolean[]> = SomeExtend<T, true>;
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
> **Rule catalog ID:** R080
|
|
101
|
+
|
|
102
|
+
## Further reading
|
|
103
|
+
|
|
104
|
+
- [`type-fest` README](https://github.com/sindresorhus/type-fest)
|
|
105
|
+
- [`type-fest` npm documentation](https://www.npmjs.com/package/type-fest)
|
|
106
|
+
- [TypeScript Handbook: Conditional Types](https://www.typescriptlang.org/docs/handbook/2/conditional-types.html)
|
|
107
|
+
|
|
108
|
+
## Adoption resources
|
|
109
|
+
|
|
110
|
+
- [Rule adoption checklist](./guides/adoption-checklist.md)
|
|
111
|
+
- [Rollout and fix safety](./guides/rollout-and-fix-safety.md)
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
# prefer-type-fest-union-member
|
|
2
|
+
|
|
3
|
+
Require TypeFest [`UnionMember<T>`](https://github.com/sindresorhus/type-fest/blob/main/source/union-member.d.ts) over custom union-member extraction helpers based on `UnionToIntersection`.
|
|
4
|
+
|
|
5
|
+
## Targeted pattern scope
|
|
6
|
+
|
|
7
|
+
This rule targets exact custom helper definitions that reproduce TypeFest `UnionMember<T>` semantics with `UnionToIntersection`, distributive function wrappers, and the optional `IsNever<T>` guard.
|
|
8
|
+
|
|
9
|
+
## What this rule reports
|
|
10
|
+
|
|
11
|
+
- `UnionToIntersection<T extends any ? () => T : never> extends () => infer R ? R : never`
|
|
12
|
+
- The guarded variant `IsNever<T> extends true ? never : ...`
|
|
13
|
+
|
|
14
|
+
## Why this rule exists
|
|
15
|
+
|
|
16
|
+
`UnionMember<T>` is the canonical TypeFest helper for extracting an arbitrary union member. Using it avoids re-declaring a brittle conditional-type helper and standardizes on the TypeFest utility name.
|
|
17
|
+
|
|
18
|
+
## ❌ Incorrect
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
type LastOfUnion<Union> = IsNever<Union> extends true
|
|
22
|
+
? never
|
|
23
|
+
: UnionToIntersection<Union extends any ? () => Union : never> extends () => infer Last
|
|
24
|
+
? Last
|
|
25
|
+
: never;
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## ✅ Correct
|
|
29
|
+
|
|
30
|
+
```ts
|
|
31
|
+
import type { UnionMember } from "type-fest";
|
|
32
|
+
|
|
33
|
+
type LastOfUnion<Union> = UnionMember<Union>;
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Behavior and migration notes
|
|
37
|
+
|
|
38
|
+
- This rule intentionally matches only exact, high-confidence helper shapes.
|
|
39
|
+
- Similar custom helpers that differ structurally are ignored.
|
|
40
|
+
- It will not autofix when `UnionMember` is shadowed in the local type scope.
|
|
41
|
+
|
|
42
|
+
## Additional examples
|
|
43
|
+
|
|
44
|
+
### ❌ Incorrect — Additional example
|
|
45
|
+
|
|
46
|
+
```ts
|
|
47
|
+
type MemberOfUnion<Union> = UnionToIntersection<Union extends any ? () => Union : never> extends () => infer Member
|
|
48
|
+
? Member
|
|
49
|
+
: never;
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### ✅ Correct — Additional example
|
|
53
|
+
|
|
54
|
+
```ts
|
|
55
|
+
import type { UnionMember } from "type-fest";
|
|
56
|
+
|
|
57
|
+
type MemberOfUnion<Union> = UnionMember<Union>;
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### ✅ Correct — Non-targeted usage
|
|
61
|
+
|
|
62
|
+
```ts
|
|
63
|
+
type LastOfUnion<Union> = UnionToIntersection<Union extends unknown ? () => Union : never> extends () => infer Last
|
|
64
|
+
? Last
|
|
65
|
+
: never;
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## ESLint flat config example
|
|
69
|
+
|
|
70
|
+
```ts
|
|
71
|
+
import typefest from "eslint-plugin-typefest";
|
|
72
|
+
|
|
73
|
+
export default [
|
|
74
|
+
{
|
|
75
|
+
plugins: { typefest },
|
|
76
|
+
rules: {
|
|
77
|
+
"typefest/prefer-type-fest-union-member": "error",
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
];
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## When not to use it
|
|
84
|
+
|
|
85
|
+
Disable this rule if your project intentionally keeps local helper names for compatibility or if your custom helper intentionally differs from TypeFest `UnionMember<T>` semantics.
|
|
86
|
+
|
|
87
|
+
## Package documentation
|
|
88
|
+
|
|
89
|
+
TypeFest package documentation:
|
|
90
|
+
|
|
91
|
+
Source file: [`source/union-member.d.ts`](https://github.com/sindresorhus/type-fest/blob/main/source/union-member.d.ts)
|
|
92
|
+
|
|
93
|
+
```ts
|
|
94
|
+
/**
|
|
95
|
+
Returns an arbitrary member of a union type.
|
|
96
|
+
|
|
97
|
+
Use-cases:
|
|
98
|
+
- Implementing recursive type functions that accept a union type.
|
|
99
|
+
*/
|
|
100
|
+
export type UnionMember<T> =
|
|
101
|
+
IsNever<T> extends true
|
|
102
|
+
? never
|
|
103
|
+
: UnionToIntersection<T extends any ? () => T : never> extends () => (infer R)
|
|
104
|
+
? R
|
|
105
|
+
: never;
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
> **Rule catalog ID:** R081
|
|
109
|
+
|
|
110
|
+
## Further reading
|
|
111
|
+
|
|
112
|
+
- [`type-fest` README](https://github.com/sindresorhus/type-fest)
|
|
113
|
+
- [`type-fest` npm documentation](https://www.npmjs.com/package/type-fest)
|
|
114
|
+
- [TypeScript Handbook: Conditional Types](https://www.typescriptlang.org/docs/handbook/2/conditional-types.html)
|
|
115
|
+
|
|
116
|
+
## Adoption resources
|
|
117
|
+
|
|
118
|
+
- [Rule adoption checklist](./guides/adoption-checklist.md)
|
|
119
|
+
- [Rollout and fix safety](./guides/rollout-and-fix-safety.md)
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
# prefer-type-fest-union-to-tuple
|
|
2
|
+
|
|
3
|
+
Require TypeFest [`UnionToTuple<T>`](https://github.com/sindresorhus/type-fest/blob/main/source/union-to-tuple.d.ts) over legacy union-to-tuple aliases.
|
|
4
|
+
|
|
5
|
+
## Targeted pattern scope
|
|
6
|
+
|
|
7
|
+
This rule targets imported alias names that represent union-to-tuple conversion semantics (for example, `TuplifyUnion` and `TupleFromUnion`).
|
|
8
|
+
|
|
9
|
+
## What this rule reports
|
|
10
|
+
|
|
11
|
+
- Type references that resolve to imported union-to-tuple aliases.
|
|
12
|
+
|
|
13
|
+
## Why this rule exists
|
|
14
|
+
|
|
15
|
+
`UnionToTuple` is TypeFest’s canonical helper for converting unions to tuple forms. Using one canonical helper improves readability and migration consistency.
|
|
16
|
+
|
|
17
|
+
## ❌ Incorrect
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import type { TuplifyUnion } from "type-aliases";
|
|
21
|
+
|
|
22
|
+
type KeysTuple = TuplifyUnion<"a" | "b" | "c">;
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## ✅ Correct
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
import type { UnionToTuple } from "type-fest";
|
|
29
|
+
|
|
30
|
+
type KeysTuple = UnionToTuple<"a" | "b" | "c">;
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Behavior and migration notes
|
|
34
|
+
|
|
35
|
+
- `UnionToTuple<T>` converts union members into an unordered tuple.
|
|
36
|
+
- This rule only targets known alias names with equivalent intent.
|
|
37
|
+
- Keep custom aliases only when they intentionally provide additional behavior.
|
|
38
|
+
|
|
39
|
+
## Additional examples
|
|
40
|
+
|
|
41
|
+
### ❌ Incorrect — Additional example
|
|
42
|
+
|
|
43
|
+
```ts
|
|
44
|
+
import type { TupleFromUnion } from "type-aliases";
|
|
45
|
+
|
|
46
|
+
type NumericTuple = TupleFromUnion<1 | 2 | 3>;
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### ✅ Correct — Additional example
|
|
50
|
+
|
|
51
|
+
```ts
|
|
52
|
+
import type { UnionToTuple } from "type-fest";
|
|
53
|
+
|
|
54
|
+
type NumericTuple = UnionToTuple<1 | 2 | 3>;
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### ✅ Correct — Repository-wide usage
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
type AllowedTuple = UnionToTuple<AllowedValue>;
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## ESLint flat config example
|
|
64
|
+
|
|
65
|
+
```ts
|
|
66
|
+
import typefest from "eslint-plugin-typefest";
|
|
67
|
+
|
|
68
|
+
export default [
|
|
69
|
+
{
|
|
70
|
+
plugins: { typefest },
|
|
71
|
+
rules: {
|
|
72
|
+
"typefest/prefer-type-fest-union-to-tuple": "error",
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
];
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## When not to use it
|
|
79
|
+
|
|
80
|
+
Disable this rule if compatibility requirements mandate custom alias names.
|
|
81
|
+
|
|
82
|
+
## Package documentation
|
|
83
|
+
|
|
84
|
+
TypeFest package documentation:
|
|
85
|
+
|
|
86
|
+
Source file: [`source/union-to-tuple.d.ts`](https://github.com/sindresorhus/type-fest/blob/main/source/union-to-tuple.d.ts)
|
|
87
|
+
|
|
88
|
+
```ts
|
|
89
|
+
/**
|
|
90
|
+
Convert a union type into an unordered tuple type of its elements.
|
|
91
|
+
|
|
92
|
+
@category Array
|
|
93
|
+
*/
|
|
94
|
+
export type UnionToTuple<T, L = UnionMember<T>> = ...
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
> **Rule catalog ID:** R083
|
|
98
|
+
|
|
99
|
+
## Further reading
|
|
100
|
+
|
|
101
|
+
- [`type-fest` README](https://github.com/sindresorhus/type-fest)
|
|
102
|
+
- [`type-fest` npm documentation](https://www.npmjs.com/package/type-fest)
|
|
103
|
+
- [TypeScript Handbook: Unions and Intersection Types](https://www.typescriptlang.org/docs/handbook/unions-and-intersections.html)
|
|
104
|
+
|
|
105
|
+
## Adoption resources
|
|
106
|
+
|
|
107
|
+
- [Rule adoption checklist](./guides/adoption-checklist.md)
|
|
108
|
+
- [Rollout and fix safety](./guides/rollout-and-fix-safety.md)
|
|
@@ -64,9 +64,12 @@ export default [typefest.configs.all];
|
|
|
64
64
|
| [`prefer-ts-extras-set-has`](https://nick2bad4u.github.io/eslint-plugin-typefest/docs/rules/prefer-ts-extras-set-has) | 🔧 💡 |
|
|
65
65
|
| [`prefer-ts-extras-string-split`](https://nick2bad4u.github.io/eslint-plugin-typefest/docs/rules/prefer-ts-extras-string-split) | 🔧 |
|
|
66
66
|
| [`prefer-type-fest-abstract-constructor`](https://nick2bad4u.github.io/eslint-plugin-typefest/docs/rules/prefer-type-fest-abstract-constructor) | 🔧 |
|
|
67
|
+
| [`prefer-type-fest-and-all`](https://nick2bad4u.github.io/eslint-plugin-typefest/docs/rules/prefer-type-fest-and-all) | 🔧 |
|
|
68
|
+
| [`prefer-type-fest-array-length`](https://nick2bad4u.github.io/eslint-plugin-typefest/docs/rules/prefer-type-fest-array-length) | 🔧 |
|
|
67
69
|
| [`prefer-type-fest-arrayable`](https://nick2bad4u.github.io/eslint-plugin-typefest/docs/rules/prefer-type-fest-arrayable) | 🔧 |
|
|
68
70
|
| [`prefer-type-fest-async-return-type`](https://nick2bad4u.github.io/eslint-plugin-typefest/docs/rules/prefer-type-fest-async-return-type) | 🔧 |
|
|
69
71
|
| [`prefer-type-fest-conditional-pick`](https://nick2bad4u.github.io/eslint-plugin-typefest/docs/rules/prefer-type-fest-conditional-pick) | 🔧 |
|
|
72
|
+
| [`prefer-type-fest-conditional-pick-deep`](https://nick2bad4u.github.io/eslint-plugin-typefest/docs/rules/prefer-type-fest-conditional-pick-deep) | 🔧 |
|
|
70
73
|
| [`prefer-type-fest-constructor`](https://nick2bad4u.github.io/eslint-plugin-typefest/docs/rules/prefer-type-fest-constructor) | 🔧 |
|
|
71
74
|
| [`prefer-type-fest-except`](https://nick2bad4u.github.io/eslint-plugin-typefest/docs/rules/prefer-type-fest-except) | 🔧 |
|
|
72
75
|
| [`prefer-type-fest-if`](https://nick2bad4u.github.io/eslint-plugin-typefest/docs/rules/prefer-type-fest-if) | 🔧 |
|
|
@@ -76,10 +79,14 @@ export default [typefest.configs.all];
|
|
|
76
79
|
| [`prefer-type-fest-json-primitive`](https://nick2bad4u.github.io/eslint-plugin-typefest/docs/rules/prefer-type-fest-json-primitive) | 🔧 |
|
|
77
80
|
| [`prefer-type-fest-json-value`](https://nick2bad4u.github.io/eslint-plugin-typefest/docs/rules/prefer-type-fest-json-value) | 💡 |
|
|
78
81
|
| [`prefer-type-fest-keys-of-union`](https://nick2bad4u.github.io/eslint-plugin-typefest/docs/rules/prefer-type-fest-keys-of-union) | 🔧 |
|
|
82
|
+
| [`prefer-type-fest-less-than`](https://nick2bad4u.github.io/eslint-plugin-typefest/docs/rules/prefer-type-fest-less-than) | 🔧 |
|
|
83
|
+
| [`prefer-type-fest-less-than-or-equal`](https://nick2bad4u.github.io/eslint-plugin-typefest/docs/rules/prefer-type-fest-less-than-or-equal) | 🔧 |
|
|
79
84
|
| [`prefer-type-fest-literal-union`](https://nick2bad4u.github.io/eslint-plugin-typefest/docs/rules/prefer-type-fest-literal-union) | 🔧 |
|
|
80
85
|
| [`prefer-type-fest-merge-exclusive`](https://nick2bad4u.github.io/eslint-plugin-typefest/docs/rules/prefer-type-fest-merge-exclusive) | 🔧 |
|
|
81
86
|
| [`prefer-type-fest-non-empty-tuple`](https://nick2bad4u.github.io/eslint-plugin-typefest/docs/rules/prefer-type-fest-non-empty-tuple) | 🔧 |
|
|
82
87
|
| [`prefer-type-fest-omit-index-signature`](https://nick2bad4u.github.io/eslint-plugin-typefest/docs/rules/prefer-type-fest-omit-index-signature) | 🔧 |
|
|
88
|
+
| [`prefer-type-fest-optional`](https://nick2bad4u.github.io/eslint-plugin-typefest/docs/rules/prefer-type-fest-optional) | 🔧 |
|
|
89
|
+
| [`prefer-type-fest-or-all`](https://nick2bad4u.github.io/eslint-plugin-typefest/docs/rules/prefer-type-fest-or-all) | 🔧 |
|
|
83
90
|
| [`prefer-type-fest-partial-deep`](https://nick2bad4u.github.io/eslint-plugin-typefest/docs/rules/prefer-type-fest-partial-deep) | 🔧 |
|
|
84
91
|
| [`prefer-type-fest-primitive`](https://nick2bad4u.github.io/eslint-plugin-typefest/docs/rules/prefer-type-fest-primitive) | 🔧 |
|
|
85
92
|
| [`prefer-type-fest-promisable`](https://nick2bad4u.github.io/eslint-plugin-typefest/docs/rules/prefer-type-fest-promisable) | 🔧 |
|
|
@@ -97,6 +104,8 @@ export default [typefest.configs.all];
|
|
|
97
104
|
| [`prefer-type-fest-simplify`](https://nick2bad4u.github.io/eslint-plugin-typefest/docs/rules/prefer-type-fest-simplify) | 🔧 |
|
|
98
105
|
| [`prefer-type-fest-tagged-brands`](https://nick2bad4u.github.io/eslint-plugin-typefest/docs/rules/prefer-type-fest-tagged-brands) | 🔧 |
|
|
99
106
|
| [`prefer-type-fest-tuple-of`](https://nick2bad4u.github.io/eslint-plugin-typefest/docs/rules/prefer-type-fest-tuple-of) | 🔧 |
|
|
107
|
+
| [`prefer-type-fest-union-member`](https://nick2bad4u.github.io/eslint-plugin-typefest/docs/rules/prefer-type-fest-union-member) | 🔧 |
|
|
108
|
+
| [`prefer-type-fest-union-to-tuple`](https://nick2bad4u.github.io/eslint-plugin-typefest/docs/rules/prefer-type-fest-union-to-tuple) | 🔧 |
|
|
100
109
|
| [`prefer-type-fest-unknown-array`](https://nick2bad4u.github.io/eslint-plugin-typefest/docs/rules/prefer-type-fest-unknown-array) | 🔧 |
|
|
101
110
|
| [`prefer-type-fest-unknown-map`](https://nick2bad4u.github.io/eslint-plugin-typefest/docs/rules/prefer-type-fest-unknown-map) | 🔧 |
|
|
102
111
|
| [`prefer-type-fest-unknown-record`](https://nick2bad4u.github.io/eslint-plugin-typefest/docs/rules/prefer-type-fest-unknown-record) | 🔧 |
|