@eslint-react/shared 2.0.0-next.8 → 2.0.0
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/dist/index.d.ts +115 -1037
- package/dist/index.js +163 -237
- package/package.json +11 -12
package/dist/index.d.ts
CHANGED
|
@@ -1,17 +1,22 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import { unit } from "@eslint-react/eff";
|
|
2
|
+
import * as _eslint_react_kit0 from "@eslint-react/kit";
|
|
3
|
+
import { CompatibleConfig, CompatiblePlugin, RuleContext } from "@eslint-react/kit";
|
|
4
|
+
import { z } from "zod/v4";
|
|
5
|
+
import { PartialDeep } from "type-fest";
|
|
4
6
|
|
|
7
|
+
//#region src/_id.d.ts
|
|
5
8
|
/**
|
|
6
9
|
* @internal
|
|
7
10
|
*/
|
|
8
11
|
declare const getId: () => string;
|
|
9
|
-
|
|
12
|
+
//#endregion
|
|
13
|
+
//#region src/_require.d.ts
|
|
10
14
|
/**
|
|
11
15
|
* @internal
|
|
12
16
|
*/
|
|
13
17
|
declare const _require: NodeJS.Require;
|
|
14
|
-
|
|
18
|
+
//#endregion
|
|
19
|
+
//#region src/constants.d.ts
|
|
15
20
|
/**
|
|
16
21
|
* The NPM scope for this project.
|
|
17
22
|
*/
|
|
@@ -24,7 +29,26 @@ declare const GITHUB_URL = "https://github.com/Rel1cx/eslint-react";
|
|
|
24
29
|
* The URL to the project's website.
|
|
25
30
|
*/
|
|
26
31
|
declare const WEBSITE_URL = "https://eslint-react.xyz";
|
|
27
|
-
|
|
32
|
+
//#endregion
|
|
33
|
+
//#region src/get-config-adapters.d.ts
|
|
34
|
+
declare function getConfigAdapters(pluginName: string, plugin: CompatiblePlugin): {
|
|
35
|
+
readonly toFlatConfig: (config: CompatibleConfig) => {
|
|
36
|
+
plugins: {
|
|
37
|
+
[pluginName]: CompatiblePlugin;
|
|
38
|
+
};
|
|
39
|
+
name?: string;
|
|
40
|
+
rules?: Record<string, _eslint_react_kit0.RuleConfig>;
|
|
41
|
+
settings?: _eslint_react_kit0.SettingsConfig;
|
|
42
|
+
};
|
|
43
|
+
readonly toLegacyConfig: ({
|
|
44
|
+
rules
|
|
45
|
+
}: CompatibleConfig) => {
|
|
46
|
+
plugins: string[];
|
|
47
|
+
rules: Record<string, _eslint_react_kit0.RuleConfig<unknown[]>> | undefined;
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
//#endregion
|
|
51
|
+
//#region src/get-doc-url.d.ts
|
|
28
52
|
/**
|
|
29
53
|
* Get the URL for the documentation of a rule in a plugin.
|
|
30
54
|
* @internal
|
|
@@ -32,1060 +56,114 @@ declare const WEBSITE_URL = "https://eslint-react.xyz";
|
|
|
32
56
|
* @returns The URL for the documentation of a rule.
|
|
33
57
|
*/
|
|
34
58
|
declare const getDocsUrl: (pluginName: string) => (ruleName: string) => string;
|
|
35
|
-
|
|
59
|
+
//#endregion
|
|
60
|
+
//#region src/get-react-version.d.ts
|
|
36
61
|
declare function getReactVersion(fallback: string): string;
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
Matches any [primitive value](https://developer.mozilla.org/en-US/docs/Glossary/Primitive).
|
|
40
|
-
|
|
41
|
-
@category Type
|
|
42
|
-
*/
|
|
43
|
-
type Primitive =
|
|
44
|
-
| null
|
|
45
|
-
| undefined
|
|
46
|
-
| string
|
|
47
|
-
| number
|
|
48
|
-
| boolean
|
|
49
|
-
| symbol
|
|
50
|
-
| bigint;
|
|
51
|
-
|
|
52
|
-
declare global {
|
|
53
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions -- It has to be an `interface` so that it can be merged.
|
|
54
|
-
interface SymbolConstructor {
|
|
55
|
-
readonly observable: symbol;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
Extract all optional keys from the given type.
|
|
61
|
-
|
|
62
|
-
This is useful when you want to create a new type that contains different type values for the optional keys only.
|
|
63
|
-
|
|
64
|
-
@example
|
|
65
|
-
```
|
|
66
|
-
import type {OptionalKeysOf, Except} from 'type-fest';
|
|
67
|
-
|
|
68
|
-
interface User {
|
|
69
|
-
name: string;
|
|
70
|
-
surname: string;
|
|
71
|
-
|
|
72
|
-
luckyNumber?: number;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
const REMOVE_FIELD = Symbol('remove field symbol');
|
|
76
|
-
type UpdateOperation<Entity extends object> = Except<Partial<Entity>, OptionalKeysOf<Entity>> & {
|
|
77
|
-
[Key in OptionalKeysOf<Entity>]?: Entity[Key] | typeof REMOVE_FIELD;
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
const update1: UpdateOperation<User> = {
|
|
81
|
-
name: 'Alice'
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
const update2: UpdateOperation<User> = {
|
|
85
|
-
name: 'Bob',
|
|
86
|
-
luckyNumber: REMOVE_FIELD
|
|
87
|
-
};
|
|
88
|
-
```
|
|
89
|
-
|
|
90
|
-
@category Utilities
|
|
91
|
-
*/
|
|
92
|
-
type OptionalKeysOf<BaseType extends object> =
|
|
93
|
-
BaseType extends unknown // For distributing `BaseType`
|
|
94
|
-
? (keyof {
|
|
95
|
-
[Key in keyof BaseType as BaseType extends Record<Key, BaseType[Key]> ? never : Key]: never
|
|
96
|
-
}) & (keyof BaseType) // Intersect with `keyof BaseType` to ensure result of `OptionalKeysOf<BaseType>` is always assignable to `keyof BaseType`
|
|
97
|
-
: never; // Should never happen
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
Extract all required keys from the given type.
|
|
101
|
-
|
|
102
|
-
This is useful when you want to create a new type that contains different type values for the required keys only or use the list of keys for validation purposes, etc...
|
|
103
|
-
|
|
104
|
-
@example
|
|
105
|
-
```
|
|
106
|
-
import type {RequiredKeysOf} from 'type-fest';
|
|
107
|
-
|
|
108
|
-
declare function createValidation<Entity extends object, Key extends RequiredKeysOf<Entity> = RequiredKeysOf<Entity>>(field: Key, validator: (value: Entity[Key]) => boolean): ValidatorFn;
|
|
109
|
-
|
|
110
|
-
interface User {
|
|
111
|
-
name: string;
|
|
112
|
-
surname: string;
|
|
113
|
-
|
|
114
|
-
luckyNumber?: number;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
const validator1 = createValidation<User>('name', value => value.length < 25);
|
|
118
|
-
const validator2 = createValidation<User>('surname', value => value.length < 25);
|
|
119
|
-
```
|
|
120
|
-
|
|
121
|
-
@category Utilities
|
|
122
|
-
*/
|
|
123
|
-
type RequiredKeysOf<BaseType extends object> =
|
|
124
|
-
BaseType extends unknown // For distributing `BaseType`
|
|
125
|
-
? Exclude<keyof BaseType, OptionalKeysOf<BaseType>>
|
|
126
|
-
: never; // Should never happen
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
Returns a boolean for whether the given type is `never`.
|
|
130
|
-
|
|
131
|
-
@link https://github.com/microsoft/TypeScript/issues/31751#issuecomment-498526919
|
|
132
|
-
@link https://stackoverflow.com/a/53984913/10292952
|
|
133
|
-
@link https://www.zhenghao.io/posts/ts-never
|
|
134
|
-
|
|
135
|
-
Useful in type utilities, such as checking if something does not occur.
|
|
136
|
-
|
|
137
|
-
@example
|
|
138
|
-
```
|
|
139
|
-
import type {IsNever, And} from 'type-fest';
|
|
140
|
-
|
|
141
|
-
// https://github.com/andnp/SimplyTyped/blob/master/src/types/strings.ts
|
|
142
|
-
type AreStringsEqual<A extends string, B extends string> =
|
|
143
|
-
And<
|
|
144
|
-
IsNever<Exclude<A, B>> extends true ? true : false,
|
|
145
|
-
IsNever<Exclude<B, A>> extends true ? true : false
|
|
146
|
-
>;
|
|
147
|
-
|
|
148
|
-
type EndIfEqual<I extends string, O extends string> =
|
|
149
|
-
AreStringsEqual<I, O> extends true
|
|
150
|
-
? never
|
|
151
|
-
: void;
|
|
152
|
-
|
|
153
|
-
function endIfEqual<I extends string, O extends string>(input: I, output: O): EndIfEqual<I, O> {
|
|
154
|
-
if (input === output) {
|
|
155
|
-
process.exit(0);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
endIfEqual('abc', 'abc');
|
|
160
|
-
//=> never
|
|
161
|
-
|
|
162
|
-
endIfEqual('abc', '123');
|
|
163
|
-
//=> void
|
|
164
|
-
```
|
|
165
|
-
|
|
166
|
-
@category Type Guard
|
|
167
|
-
@category Utilities
|
|
168
|
-
*/
|
|
169
|
-
type IsNever<T> = [T] extends [never] ? true : false;
|
|
170
|
-
|
|
171
|
-
/**
|
|
172
|
-
An if-else-like type that resolves depending on whether the given type is `never`.
|
|
173
|
-
|
|
174
|
-
@see {@link IsNever}
|
|
175
|
-
|
|
176
|
-
@example
|
|
177
|
-
```
|
|
178
|
-
import type {IfNever} from 'type-fest';
|
|
179
|
-
|
|
180
|
-
type ShouldBeTrue = IfNever<never>;
|
|
181
|
-
//=> true
|
|
182
|
-
|
|
183
|
-
type ShouldBeBar = IfNever<'not never', 'foo', 'bar'>;
|
|
184
|
-
//=> 'bar'
|
|
185
|
-
```
|
|
186
|
-
|
|
187
|
-
@category Type Guard
|
|
188
|
-
@category Utilities
|
|
189
|
-
*/
|
|
190
|
-
type IfNever<T, TypeIfNever = true, TypeIfNotNever = false> = (
|
|
191
|
-
IsNever<T> extends true ? TypeIfNever : TypeIfNotNever
|
|
192
|
-
);
|
|
193
|
-
|
|
194
|
-
// Can eventually be replaced with the built-in once this library supports
|
|
195
|
-
// TS5.4+ only. Tracked in https://github.com/sindresorhus/type-fest/issues/848
|
|
196
|
-
type NoInfer<T> = T extends infer U ? U : never;
|
|
197
|
-
|
|
198
|
-
/**
|
|
199
|
-
Returns a boolean for whether the given type is `any`.
|
|
200
|
-
|
|
201
|
-
@link https://stackoverflow.com/a/49928360/1490091
|
|
202
|
-
|
|
203
|
-
Useful in type utilities, such as disallowing `any`s to be passed to a function.
|
|
204
|
-
|
|
205
|
-
@example
|
|
206
|
-
```
|
|
207
|
-
import type {IsAny} from 'type-fest';
|
|
208
|
-
|
|
209
|
-
const typedObject = {a: 1, b: 2} as const;
|
|
210
|
-
const anyObject: any = {a: 1, b: 2};
|
|
211
|
-
|
|
212
|
-
function get<O extends (IsAny<O> extends true ? {} : Record<string, number>), K extends keyof O = keyof O>(obj: O, key: K) {
|
|
213
|
-
return obj[key];
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
const typedA = get(typedObject, 'a');
|
|
217
|
-
//=> 1
|
|
218
|
-
|
|
219
|
-
const anyA = get(anyObject, 'a');
|
|
220
|
-
//=> any
|
|
221
|
-
```
|
|
222
|
-
|
|
223
|
-
@category Type Guard
|
|
224
|
-
@category Utilities
|
|
225
|
-
*/
|
|
226
|
-
type IsAny<T> = 0 extends 1 & NoInfer<T> ? true : false;
|
|
227
|
-
|
|
228
|
-
/**
|
|
229
|
-
Useful to flatten the type output to improve type hints shown in editors. And also to transform an interface into a type to aide with assignability.
|
|
230
|
-
|
|
231
|
-
@example
|
|
232
|
-
```
|
|
233
|
-
import type {Simplify} from 'type-fest';
|
|
234
|
-
|
|
235
|
-
type PositionProps = {
|
|
236
|
-
top: number;
|
|
237
|
-
left: number;
|
|
238
|
-
};
|
|
239
|
-
|
|
240
|
-
type SizeProps = {
|
|
241
|
-
width: number;
|
|
242
|
-
height: number;
|
|
243
|
-
};
|
|
244
|
-
|
|
245
|
-
// In your editor, hovering over `Props` will show a flattened object with all the properties.
|
|
246
|
-
type Props = Simplify<PositionProps & SizeProps>;
|
|
247
|
-
```
|
|
248
|
-
|
|
249
|
-
Sometimes it is desired to pass a value as a function argument that has a different type. At first inspection it may seem assignable, and then you discover it is not because the `value`'s type definition was defined as an interface. In the following example, `fn` requires an argument of type `Record<string, unknown>`. If the value is defined as a literal, then it is assignable. And if the `value` is defined as type using the `Simplify` utility the value is assignable. But if the `value` is defined as an interface, it is not assignable because the interface is not sealed and elsewhere a non-string property could be added to the interface.
|
|
250
|
-
|
|
251
|
-
If the type definition must be an interface (perhaps it was defined in a third-party npm package), then the `value` can be defined as `const value: Simplify<SomeInterface> = ...`. Then `value` will be assignable to the `fn` argument. Or the `value` can be cast as `Simplify<SomeInterface>` if you can't re-declare the `value`.
|
|
252
|
-
|
|
253
|
-
@example
|
|
254
|
-
```
|
|
255
|
-
import type {Simplify} from 'type-fest';
|
|
256
|
-
|
|
257
|
-
interface SomeInterface {
|
|
258
|
-
foo: number;
|
|
259
|
-
bar?: string;
|
|
260
|
-
baz: number | undefined;
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
type SomeType = {
|
|
264
|
-
foo: number;
|
|
265
|
-
bar?: string;
|
|
266
|
-
baz: number | undefined;
|
|
267
|
-
};
|
|
268
|
-
|
|
269
|
-
const literal = {foo: 123, bar: 'hello', baz: 456};
|
|
270
|
-
const someType: SomeType = literal;
|
|
271
|
-
const someInterface: SomeInterface = literal;
|
|
272
|
-
|
|
273
|
-
function fn(object: Record<string, unknown>): void {}
|
|
274
|
-
|
|
275
|
-
fn(literal); // Good: literal object type is sealed
|
|
276
|
-
fn(someType); // Good: type is sealed
|
|
277
|
-
fn(someInterface); // Error: Index signature for type 'string' is missing in type 'someInterface'. Because `interface` can be re-opened
|
|
278
|
-
fn(someInterface as Simplify<SomeInterface>); // Good: transform an `interface` into a `type`
|
|
279
|
-
```
|
|
280
|
-
|
|
281
|
-
@link https://github.com/microsoft/TypeScript/issues/15300
|
|
282
|
-
@see SimplifyDeep
|
|
283
|
-
@category Object
|
|
284
|
-
*/
|
|
285
|
-
type Simplify<T> = {[KeyType in keyof T]: T[KeyType]} & {};
|
|
286
|
-
|
|
287
|
-
/**
|
|
288
|
-
Omit any index signatures from the given object type, leaving only explicitly defined properties.
|
|
289
|
-
|
|
290
|
-
This is the counterpart of `PickIndexSignature`.
|
|
291
|
-
|
|
292
|
-
Use-cases:
|
|
293
|
-
- Remove overly permissive signatures from third-party types.
|
|
294
|
-
|
|
295
|
-
This type was taken from this [StackOverflow answer](https://stackoverflow.com/a/68261113/420747).
|
|
296
|
-
|
|
297
|
-
It relies on the fact that an empty object (`{}`) is assignable to an object with just an index signature, like `Record<string, unknown>`, but not to an object with explicitly defined keys, like `Record<'foo' | 'bar', unknown>`.
|
|
298
|
-
|
|
299
|
-
(The actual value type, `unknown`, is irrelevant and could be any type. Only the key type matters.)
|
|
300
|
-
|
|
301
|
-
```
|
|
302
|
-
const indexed: Record<string, unknown> = {}; // Allowed
|
|
303
|
-
|
|
304
|
-
const keyed: Record<'foo', unknown> = {}; // Error
|
|
305
|
-
// => TS2739: Type '{}' is missing the following properties from type 'Record<"foo" | "bar", unknown>': foo, bar
|
|
306
|
-
```
|
|
307
|
-
|
|
308
|
-
Instead of causing a type error like the above, you can also use a [conditional type](https://www.typescriptlang.org/docs/handbook/2/conditional-types.html) to test whether a type is assignable to another:
|
|
309
|
-
|
|
310
|
-
```
|
|
311
|
-
type Indexed = {} extends Record<string, unknown>
|
|
312
|
-
? '✅ `{}` is assignable to `Record<string, unknown>`'
|
|
313
|
-
: '❌ `{}` is NOT assignable to `Record<string, unknown>`';
|
|
314
|
-
// => '✅ `{}` is assignable to `Record<string, unknown>`'
|
|
315
|
-
|
|
316
|
-
type Keyed = {} extends Record<'foo' | 'bar', unknown>
|
|
317
|
-
? "✅ `{}` is assignable to `Record<'foo' | 'bar', unknown>`"
|
|
318
|
-
: "❌ `{}` is NOT assignable to `Record<'foo' | 'bar', unknown>`";
|
|
319
|
-
// => "❌ `{}` is NOT assignable to `Record<'foo' | 'bar', unknown>`"
|
|
320
|
-
```
|
|
321
|
-
|
|
322
|
-
Using a [mapped type](https://www.typescriptlang.org/docs/handbook/2/mapped-types.html#further-exploration), you can then check for each `KeyType` of `ObjectType`...
|
|
323
|
-
|
|
324
|
-
```
|
|
325
|
-
import type {OmitIndexSignature} from 'type-fest';
|
|
326
|
-
|
|
327
|
-
type OmitIndexSignature<ObjectType> = {
|
|
328
|
-
[KeyType in keyof ObjectType // Map each key of `ObjectType`...
|
|
329
|
-
]: ObjectType[KeyType]; // ...to its original value, i.e. `OmitIndexSignature<Foo> == Foo`.
|
|
330
|
-
};
|
|
331
|
-
```
|
|
332
|
-
|
|
333
|
-
...whether an empty object (`{}`) would be assignable to an object with that `KeyType` (`Record<KeyType, unknown>`)...
|
|
334
|
-
|
|
335
|
-
```
|
|
336
|
-
import type {OmitIndexSignature} from 'type-fest';
|
|
337
|
-
|
|
338
|
-
type OmitIndexSignature<ObjectType> = {
|
|
339
|
-
[KeyType in keyof ObjectType
|
|
340
|
-
// Is `{}` assignable to `Record<KeyType, unknown>`?
|
|
341
|
-
as {} extends Record<KeyType, unknown>
|
|
342
|
-
? ... // ✅ `{}` is assignable to `Record<KeyType, unknown>`
|
|
343
|
-
: ... // ❌ `{}` is NOT assignable to `Record<KeyType, unknown>`
|
|
344
|
-
]: ObjectType[KeyType];
|
|
345
|
-
};
|
|
346
|
-
```
|
|
347
|
-
|
|
348
|
-
If `{}` is assignable, it means that `KeyType` is an index signature and we want to remove it. If it is not assignable, `KeyType` is a "real" key and we want to keep it.
|
|
349
|
-
|
|
350
|
-
@example
|
|
351
|
-
```
|
|
352
|
-
import type {OmitIndexSignature} from 'type-fest';
|
|
353
|
-
|
|
354
|
-
interface Example {
|
|
355
|
-
// These index signatures will be removed.
|
|
356
|
-
[x: string]: any
|
|
357
|
-
[x: number]: any
|
|
358
|
-
[x: symbol]: any
|
|
359
|
-
[x: `head-${string}`]: string
|
|
360
|
-
[x: `${string}-tail`]: string
|
|
361
|
-
[x: `head-${string}-tail`]: string
|
|
362
|
-
[x: `${bigint}`]: string
|
|
363
|
-
[x: `embedded-${number}`]: string
|
|
364
|
-
|
|
365
|
-
// These explicitly defined keys will remain.
|
|
366
|
-
foo: 'bar';
|
|
367
|
-
qux?: 'baz';
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
type ExampleWithoutIndexSignatures = OmitIndexSignature<Example>;
|
|
371
|
-
// => { foo: 'bar'; qux?: 'baz' | undefined; }
|
|
372
|
-
```
|
|
373
|
-
|
|
374
|
-
@see PickIndexSignature
|
|
375
|
-
@category Object
|
|
376
|
-
*/
|
|
377
|
-
type OmitIndexSignature<ObjectType> = {
|
|
378
|
-
[KeyType in keyof ObjectType as {} extends Record<KeyType, unknown>
|
|
379
|
-
? never
|
|
380
|
-
: KeyType]: ObjectType[KeyType];
|
|
381
|
-
};
|
|
382
|
-
|
|
383
|
-
/**
|
|
384
|
-
Pick only index signatures from the given object type, leaving out all explicitly defined properties.
|
|
385
|
-
|
|
386
|
-
This is the counterpart of `OmitIndexSignature`.
|
|
387
|
-
|
|
388
|
-
@example
|
|
389
|
-
```
|
|
390
|
-
import type {PickIndexSignature} from 'type-fest';
|
|
391
|
-
|
|
392
|
-
declare const symbolKey: unique symbol;
|
|
393
|
-
|
|
394
|
-
type Example = {
|
|
395
|
-
// These index signatures will remain.
|
|
396
|
-
[x: string]: unknown;
|
|
397
|
-
[x: number]: unknown;
|
|
398
|
-
[x: symbol]: unknown;
|
|
399
|
-
[x: `head-${string}`]: string;
|
|
400
|
-
[x: `${string}-tail`]: string;
|
|
401
|
-
[x: `head-${string}-tail`]: string;
|
|
402
|
-
[x: `${bigint}`]: string;
|
|
403
|
-
[x: `embedded-${number}`]: string;
|
|
404
|
-
|
|
405
|
-
// These explicitly defined keys will be removed.
|
|
406
|
-
['kebab-case-key']: string;
|
|
407
|
-
[symbolKey]: string;
|
|
408
|
-
foo: 'bar';
|
|
409
|
-
qux?: 'baz';
|
|
410
|
-
};
|
|
411
|
-
|
|
412
|
-
type ExampleIndexSignature = PickIndexSignature<Example>;
|
|
413
|
-
// {
|
|
414
|
-
// [x: string]: unknown;
|
|
415
|
-
// [x: number]: unknown;
|
|
416
|
-
// [x: symbol]: unknown;
|
|
417
|
-
// [x: `head-${string}`]: string;
|
|
418
|
-
// [x: `${string}-tail`]: string;
|
|
419
|
-
// [x: `head-${string}-tail`]: string;
|
|
420
|
-
// [x: `${bigint}`]: string;
|
|
421
|
-
// [x: `embedded-${number}`]: string;
|
|
422
|
-
// }
|
|
423
|
-
```
|
|
424
|
-
|
|
425
|
-
@see OmitIndexSignature
|
|
426
|
-
@category Object
|
|
427
|
-
*/
|
|
428
|
-
type PickIndexSignature<ObjectType> = {
|
|
429
|
-
[KeyType in keyof ObjectType as {} extends Record<KeyType, unknown>
|
|
430
|
-
? KeyType
|
|
431
|
-
: never]: ObjectType[KeyType];
|
|
432
|
-
};
|
|
433
|
-
|
|
434
|
-
// Merges two objects without worrying about index signatures.
|
|
435
|
-
type SimpleMerge<Destination, Source> = {
|
|
436
|
-
[Key in keyof Destination as Key extends keyof Source ? never : Key]: Destination[Key];
|
|
437
|
-
} & Source;
|
|
438
|
-
|
|
439
|
-
/**
|
|
440
|
-
Merge two types into a new type. Keys of the second type overrides keys of the first type.
|
|
441
|
-
|
|
442
|
-
@example
|
|
443
|
-
```
|
|
444
|
-
import type {Merge} from 'type-fest';
|
|
445
|
-
|
|
446
|
-
interface Foo {
|
|
447
|
-
[x: string]: unknown;
|
|
448
|
-
[x: number]: unknown;
|
|
449
|
-
foo: string;
|
|
450
|
-
bar: symbol;
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
type Bar = {
|
|
454
|
-
[x: number]: number;
|
|
455
|
-
[x: symbol]: unknown;
|
|
456
|
-
bar: Date;
|
|
457
|
-
baz: boolean;
|
|
458
|
-
};
|
|
459
|
-
|
|
460
|
-
export type FooBar = Merge<Foo, Bar>;
|
|
461
|
-
// => {
|
|
462
|
-
// [x: string]: unknown;
|
|
463
|
-
// [x: number]: number;
|
|
464
|
-
// [x: symbol]: unknown;
|
|
465
|
-
// foo: string;
|
|
466
|
-
// bar: Date;
|
|
467
|
-
// baz: boolean;
|
|
468
|
-
// }
|
|
469
|
-
```
|
|
470
|
-
|
|
471
|
-
@category Object
|
|
472
|
-
*/
|
|
473
|
-
type Merge<Destination, Source> =
|
|
474
|
-
Simplify<
|
|
475
|
-
SimpleMerge<PickIndexSignature<Destination>, PickIndexSignature<Source>>
|
|
476
|
-
& SimpleMerge<OmitIndexSignature<Destination>, OmitIndexSignature<Source>>
|
|
477
|
-
>;
|
|
478
|
-
|
|
479
|
-
/**
|
|
480
|
-
An if-else-like type that resolves depending on whether the given type is `any`.
|
|
481
|
-
|
|
482
|
-
@see {@link IsAny}
|
|
483
|
-
|
|
484
|
-
@example
|
|
485
|
-
```
|
|
486
|
-
import type {IfAny} from 'type-fest';
|
|
487
|
-
|
|
488
|
-
type ShouldBeTrue = IfAny<any>;
|
|
489
|
-
//=> true
|
|
490
|
-
|
|
491
|
-
type ShouldBeBar = IfAny<'not any', 'foo', 'bar'>;
|
|
492
|
-
//=> 'bar'
|
|
493
|
-
```
|
|
494
|
-
|
|
495
|
-
@category Type Guard
|
|
496
|
-
@category Utilities
|
|
497
|
-
*/
|
|
498
|
-
type IfAny<T, TypeIfAny = true, TypeIfNotAny = false> = (
|
|
499
|
-
IsAny<T> extends true ? TypeIfAny : TypeIfNotAny
|
|
500
|
-
);
|
|
501
|
-
|
|
502
|
-
/**
|
|
503
|
-
Matches any primitive, `void`, `Date`, or `RegExp` value.
|
|
504
|
-
*/
|
|
505
|
-
type BuiltIns = Primitive | void | Date | RegExp;
|
|
506
|
-
|
|
507
|
-
/**
|
|
508
|
-
Merges user specified options with default options.
|
|
509
|
-
|
|
510
|
-
@example
|
|
511
|
-
```
|
|
512
|
-
type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
|
|
513
|
-
type DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: false};
|
|
514
|
-
type SpecifiedOptions = {leavesOnly: true};
|
|
515
|
-
|
|
516
|
-
type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
|
|
517
|
-
//=> {maxRecursionDepth: 10; leavesOnly: true}
|
|
518
|
-
```
|
|
519
|
-
|
|
520
|
-
@example
|
|
521
|
-
```
|
|
522
|
-
// Complains if default values are not provided for optional options
|
|
523
|
-
|
|
524
|
-
type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
|
|
525
|
-
type DefaultPathsOptions = {maxRecursionDepth: 10};
|
|
526
|
-
type SpecifiedOptions = {};
|
|
527
|
-
|
|
528
|
-
type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
|
|
529
|
-
// ~~~~~~~~~~~~~~~~~~~
|
|
530
|
-
// Property 'leavesOnly' is missing in type 'DefaultPathsOptions' but required in type '{ maxRecursionDepth: number; leavesOnly: boolean; }'.
|
|
531
|
-
```
|
|
532
|
-
|
|
533
|
-
@example
|
|
534
|
-
```
|
|
535
|
-
// Complains if an option's default type does not conform to the expected type
|
|
536
|
-
|
|
537
|
-
type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
|
|
538
|
-
type DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: 'no'};
|
|
539
|
-
type SpecifiedOptions = {};
|
|
540
|
-
|
|
541
|
-
type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
|
|
542
|
-
// ~~~~~~~~~~~~~~~~~~~
|
|
543
|
-
// Types of property 'leavesOnly' are incompatible. Type 'string' is not assignable to type 'boolean'.
|
|
544
|
-
```
|
|
545
|
-
|
|
546
|
-
@example
|
|
547
|
-
```
|
|
548
|
-
// Complains if an option's specified type does not conform to the expected type
|
|
549
|
-
|
|
550
|
-
type PathsOptions = {maxRecursionDepth?: number; leavesOnly?: boolean};
|
|
551
|
-
type DefaultPathsOptions = {maxRecursionDepth: 10; leavesOnly: false};
|
|
552
|
-
type SpecifiedOptions = {leavesOnly: 'yes'};
|
|
553
|
-
|
|
554
|
-
type Result = ApplyDefaultOptions<PathsOptions, DefaultPathsOptions, SpecifiedOptions>;
|
|
555
|
-
// ~~~~~~~~~~~~~~~~
|
|
556
|
-
// Types of property 'leavesOnly' are incompatible. Type 'string' is not assignable to type 'boolean'.
|
|
557
|
-
```
|
|
558
|
-
*/
|
|
559
|
-
type ApplyDefaultOptions<
|
|
560
|
-
Options extends object,
|
|
561
|
-
Defaults extends Simplify<Omit<Required<Options>, RequiredKeysOf<Options>> & Partial<Record<RequiredKeysOf<Options>, never>>>,
|
|
562
|
-
SpecifiedOptions extends Options,
|
|
563
|
-
> =
|
|
564
|
-
IfAny<SpecifiedOptions, Defaults,
|
|
565
|
-
IfNever<SpecifiedOptions, Defaults,
|
|
566
|
-
Simplify<Merge<Defaults, {
|
|
567
|
-
[Key in keyof SpecifiedOptions
|
|
568
|
-
as Key extends OptionalKeysOf<Options>
|
|
569
|
-
? Extract<SpecifiedOptions[Key], undefined> extends never
|
|
570
|
-
? Key
|
|
571
|
-
: never
|
|
572
|
-
: Key
|
|
573
|
-
]: SpecifiedOptions[Key]
|
|
574
|
-
}> & Required<Options>> // `& Required<Options>` ensures that `ApplyDefaultOptions<SomeOption, ...>` is always assignable to `Required<SomeOption>`
|
|
575
|
-
>>;
|
|
576
|
-
|
|
577
|
-
/**
|
|
578
|
-
@see {@link PartialDeep}
|
|
579
|
-
*/
|
|
580
|
-
type PartialDeepOptions = {
|
|
581
|
-
/**
|
|
582
|
-
Whether to affect the individual elements of arrays and tuples.
|
|
583
|
-
|
|
584
|
-
@default false
|
|
585
|
-
*/
|
|
586
|
-
readonly recurseIntoArrays?: boolean;
|
|
587
|
-
|
|
588
|
-
/**
|
|
589
|
-
Allows `undefined` values in non-tuple arrays.
|
|
590
|
-
|
|
591
|
-
- When set to `true`, elements of non-tuple arrays can be `undefined`.
|
|
592
|
-
- When set to `false`, only explicitly defined elements are allowed in non-tuple arrays, ensuring stricter type checking.
|
|
593
|
-
|
|
594
|
-
@default true
|
|
595
|
-
|
|
596
|
-
@example
|
|
597
|
-
You can prevent `undefined` values in non-tuple arrays by passing `{recurseIntoArrays: true; allowUndefinedInNonTupleArrays: false}` as the second type argument:
|
|
598
|
-
|
|
599
|
-
```
|
|
600
|
-
import type {PartialDeep} from 'type-fest';
|
|
601
|
-
|
|
602
|
-
type Settings = {
|
|
603
|
-
languages: string[];
|
|
604
|
-
};
|
|
605
|
-
|
|
606
|
-
declare const partialSettings: PartialDeep<Settings, {recurseIntoArrays: true; allowUndefinedInNonTupleArrays: false}>;
|
|
607
|
-
|
|
608
|
-
partialSettings.languages = [undefined]; // Error
|
|
609
|
-
partialSettings.languages = []; // Ok
|
|
610
|
-
```
|
|
611
|
-
*/
|
|
612
|
-
readonly allowUndefinedInNonTupleArrays?: boolean;
|
|
613
|
-
};
|
|
614
|
-
|
|
615
|
-
type DefaultPartialDeepOptions = {
|
|
616
|
-
recurseIntoArrays: false;
|
|
617
|
-
allowUndefinedInNonTupleArrays: true;
|
|
618
|
-
};
|
|
619
|
-
|
|
620
|
-
/**
|
|
621
|
-
Create a type from another type with all keys and nested keys set to optional.
|
|
622
|
-
|
|
623
|
-
Use-cases:
|
|
624
|
-
- Merging a default settings/config object with another object, the second object would be a deep partial of the default object.
|
|
625
|
-
- Mocking and testing complex entities, where populating an entire object with its keys would be redundant in terms of the mock or test.
|
|
626
|
-
|
|
627
|
-
@example
|
|
628
|
-
```
|
|
629
|
-
import type {PartialDeep} from 'type-fest';
|
|
630
|
-
|
|
631
|
-
const settings: Settings = {
|
|
632
|
-
textEditor: {
|
|
633
|
-
fontSize: 14,
|
|
634
|
-
fontColor: '#000000',
|
|
635
|
-
fontWeight: 400
|
|
636
|
-
},
|
|
637
|
-
autocomplete: false,
|
|
638
|
-
autosave: true
|
|
639
|
-
};
|
|
640
|
-
|
|
641
|
-
const applySavedSettings = (savedSettings: PartialDeep<Settings>) => {
|
|
642
|
-
return {...settings, ...savedSettings};
|
|
643
|
-
}
|
|
644
|
-
|
|
645
|
-
settings = applySavedSettings({textEditor: {fontWeight: 500}});
|
|
646
|
-
```
|
|
647
|
-
|
|
648
|
-
By default, this does not affect elements in array and tuple types. You can change this by passing `{recurseIntoArrays: true}` as the second type argument:
|
|
649
|
-
|
|
650
|
-
```
|
|
651
|
-
import type {PartialDeep} from 'type-fest';
|
|
652
|
-
|
|
653
|
-
type Settings = {
|
|
654
|
-
languages: string[];
|
|
655
|
-
}
|
|
656
|
-
|
|
657
|
-
const partialSettings: PartialDeep<Settings, {recurseIntoArrays: true}> = {
|
|
658
|
-
languages: [undefined]
|
|
659
|
-
};
|
|
660
|
-
```
|
|
661
|
-
|
|
662
|
-
@see {@link PartialDeepOptions}
|
|
663
|
-
|
|
664
|
-
@category Object
|
|
665
|
-
@category Array
|
|
666
|
-
@category Set
|
|
667
|
-
@category Map
|
|
668
|
-
*/
|
|
669
|
-
type PartialDeep<T, Options extends PartialDeepOptions = {}> =
|
|
670
|
-
_PartialDeep<T, ApplyDefaultOptions<PartialDeepOptions, DefaultPartialDeepOptions, Options>>;
|
|
671
|
-
|
|
672
|
-
type _PartialDeep<T, Options extends Required<PartialDeepOptions>> = T extends BuiltIns | ((new (...arguments_: any[]) => unknown))
|
|
673
|
-
? T
|
|
674
|
-
: IsNever<keyof T> extends true // For functions with no properties
|
|
675
|
-
? T
|
|
676
|
-
: T extends Map<infer KeyType, infer ValueType>
|
|
677
|
-
? PartialMapDeep<KeyType, ValueType, Options>
|
|
678
|
-
: T extends Set<infer ItemType>
|
|
679
|
-
? PartialSetDeep<ItemType, Options>
|
|
680
|
-
: T extends ReadonlyMap<infer KeyType, infer ValueType>
|
|
681
|
-
? PartialReadonlyMapDeep<KeyType, ValueType, Options>
|
|
682
|
-
: T extends ReadonlySet<infer ItemType>
|
|
683
|
-
? PartialReadonlySetDeep<ItemType, Options>
|
|
684
|
-
: T extends object
|
|
685
|
-
? T extends ReadonlyArray<infer ItemType> // Test for arrays/tuples, per https://github.com/microsoft/TypeScript/issues/35156
|
|
686
|
-
? Options['recurseIntoArrays'] extends true
|
|
687
|
-
? ItemType[] extends T // Test for arrays (non-tuples) specifically
|
|
688
|
-
? readonly ItemType[] extends T // Differentiate readonly and mutable arrays
|
|
689
|
-
? ReadonlyArray<_PartialDeep<Options['allowUndefinedInNonTupleArrays'] extends false ? ItemType : ItemType | undefined, Options>>
|
|
690
|
-
: Array<_PartialDeep<Options['allowUndefinedInNonTupleArrays'] extends false ? ItemType : ItemType | undefined, Options>>
|
|
691
|
-
: PartialObjectDeep<T, Options> // Tuples behave properly
|
|
692
|
-
: T // If they don't opt into array testing, just use the original type
|
|
693
|
-
: PartialObjectDeep<T, Options>
|
|
694
|
-
: unknown;
|
|
695
|
-
|
|
696
|
-
/**
|
|
697
|
-
Same as `PartialDeep`, but accepts only `Map`s and as inputs. Internal helper for `PartialDeep`.
|
|
698
|
-
*/
|
|
699
|
-
type PartialMapDeep<KeyType, ValueType, Options extends Required<PartialDeepOptions>> = {} & Map<_PartialDeep<KeyType, Options>, _PartialDeep<ValueType, Options>>;
|
|
700
|
-
|
|
701
|
-
/**
|
|
702
|
-
Same as `PartialDeep`, but accepts only `Set`s as inputs. Internal helper for `PartialDeep`.
|
|
703
|
-
*/
|
|
704
|
-
type PartialSetDeep<T, Options extends Required<PartialDeepOptions>> = {} & Set<_PartialDeep<T, Options>>;
|
|
705
|
-
|
|
706
|
-
/**
|
|
707
|
-
Same as `PartialDeep`, but accepts only `ReadonlyMap`s as inputs. Internal helper for `PartialDeep`.
|
|
708
|
-
*/
|
|
709
|
-
type PartialReadonlyMapDeep<KeyType, ValueType, Options extends Required<PartialDeepOptions>> = {} & ReadonlyMap<_PartialDeep<KeyType, Options>, _PartialDeep<ValueType, Options>>;
|
|
710
|
-
|
|
711
|
-
/**
|
|
712
|
-
Same as `PartialDeep`, but accepts only `ReadonlySet`s as inputs. Internal helper for `PartialDeep`.
|
|
713
|
-
*/
|
|
714
|
-
type PartialReadonlySetDeep<T, Options extends Required<PartialDeepOptions>> = {} & ReadonlySet<_PartialDeep<T, Options>>;
|
|
715
|
-
|
|
716
|
-
/**
|
|
717
|
-
Same as `PartialDeep`, but accepts only `object`s as inputs. Internal helper for `PartialDeep`.
|
|
718
|
-
*/
|
|
719
|
-
type PartialObjectDeep<ObjectType extends object, Options extends Required<PartialDeepOptions>> =
|
|
720
|
-
(ObjectType extends (...arguments_: any) => unknown
|
|
721
|
-
? (...arguments_: Parameters<ObjectType>) => ReturnType<ObjectType>
|
|
722
|
-
: {}) & ({
|
|
723
|
-
[KeyType in keyof ObjectType]?: _PartialDeep<ObjectType[KeyType], Options>
|
|
724
|
-
});
|
|
725
|
-
|
|
726
|
-
declare const CustomComponentPropSchema: z.ZodMiniObject<{
|
|
727
|
-
/**
|
|
728
|
-
* The name of the prop in the user-defined component.
|
|
729
|
-
* @example
|
|
730
|
-
* "to"
|
|
731
|
-
*/
|
|
732
|
-
name: z.ZodMiniString<string>;
|
|
733
|
-
/**
|
|
734
|
-
* The name of the prop in the host component.
|
|
735
|
-
* @example
|
|
736
|
-
* "href"
|
|
737
|
-
*/
|
|
738
|
-
as: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
739
|
-
/**
|
|
740
|
-
* Whether the prop is controlled or not in the user-defined component.
|
|
741
|
-
* @internal
|
|
742
|
-
* @example
|
|
743
|
-
* `true`
|
|
744
|
-
*/
|
|
745
|
-
controlled: z.ZodMiniOptional<z.ZodMiniBoolean<boolean>>;
|
|
746
|
-
/**
|
|
747
|
-
* The default value of the prop in the user-defined component.
|
|
748
|
-
* @example
|
|
749
|
-
* `"/"`
|
|
750
|
-
*/
|
|
751
|
-
defaultValue: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
752
|
-
}, {}>;
|
|
753
|
-
/**
|
|
754
|
-
* @description
|
|
755
|
-
* This will provide some key information to the rule before checking for user-defined components.
|
|
756
|
-
* For example:
|
|
757
|
-
* Which prop is used as the `href` prop for the user-defined `Link` component that represents the built-in `a` element.
|
|
758
|
-
*/
|
|
759
|
-
declare const CustomComponentSchema: z.ZodMiniObject<{
|
|
760
|
-
/**
|
|
761
|
-
* The name of the user-defined component.
|
|
762
|
-
* @example
|
|
763
|
-
* "Link"
|
|
764
|
-
*/
|
|
765
|
-
name: z.ZodMiniString<string>;
|
|
766
|
-
/**
|
|
767
|
-
* The name of the host component that the user-defined component represents.
|
|
768
|
-
* @example
|
|
769
|
-
* "a"
|
|
770
|
-
*/
|
|
771
|
-
as: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
772
|
-
/**
|
|
773
|
-
* Attributes mapping between the user-defined component and the host component.
|
|
774
|
-
* @example
|
|
775
|
-
* `Link` component has a `to` attribute that represents the `href` attribute in the built-in `a` element with a default value of `"/"`.
|
|
776
|
-
*/
|
|
777
|
-
attributes: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniObject<{
|
|
778
|
-
/**
|
|
779
|
-
* The name of the prop in the user-defined component.
|
|
780
|
-
* @example
|
|
781
|
-
* "to"
|
|
782
|
-
*/
|
|
783
|
-
name: z.ZodMiniString<string>;
|
|
784
|
-
/**
|
|
785
|
-
* The name of the prop in the host component.
|
|
786
|
-
* @example
|
|
787
|
-
* "href"
|
|
788
|
-
*/
|
|
789
|
-
as: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
790
|
-
/**
|
|
791
|
-
* Whether the prop is controlled or not in the user-defined component.
|
|
792
|
-
* @internal
|
|
793
|
-
* @example
|
|
794
|
-
* `true`
|
|
795
|
-
*/
|
|
796
|
-
controlled: z.ZodMiniOptional<z.ZodMiniBoolean<boolean>>;
|
|
797
|
-
/**
|
|
798
|
-
* The default value of the prop in the user-defined component.
|
|
799
|
-
* @example
|
|
800
|
-
* `"/"`
|
|
801
|
-
*/
|
|
802
|
-
defaultValue: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
803
|
-
}, {}>>>;
|
|
804
|
-
/**
|
|
805
|
-
* The ESQuery selector to select the component precisely.
|
|
806
|
-
* @internal
|
|
807
|
-
* @example
|
|
808
|
-
* `JSXElement:has(JSXAttribute[name.name='component'][value.value='a'])`
|
|
809
|
-
*/
|
|
810
|
-
selector: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
811
|
-
}, {}>;
|
|
812
|
-
declare const CustomHooksSchema: z.ZodMiniObject<{
|
|
813
|
-
use: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
|
|
814
|
-
useActionState: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
|
|
815
|
-
useCallback: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
|
|
816
|
-
useContext: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
|
|
817
|
-
useDebugValue: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
|
|
818
|
-
useDeferredValue: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
|
|
819
|
-
useEffect: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
|
|
820
|
-
useFormStatus: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
|
|
821
|
-
useId: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
|
|
822
|
-
useImperativeHandle: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
|
|
823
|
-
useInsertionEffect: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
|
|
824
|
-
useLayoutEffect: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
|
|
825
|
-
useMemo: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
|
|
826
|
-
useOptimistic: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
|
|
827
|
-
useReducer: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
|
|
828
|
-
useRef: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
|
|
829
|
-
useState: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
|
|
830
|
-
useSyncExternalStore: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
|
|
831
|
-
useTransition: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
|
|
832
|
-
}, {}>;
|
|
62
|
+
//#endregion
|
|
63
|
+
//#region src/settings.d.ts
|
|
833
64
|
/**
|
|
65
|
+
* Schema for ESLint React settings configuration
|
|
834
66
|
* @internal
|
|
835
67
|
*/
|
|
836
|
-
declare const ESLintReactSettingsSchema: z.
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
* @example `"@pika/react"`
|
|
842
|
-
*/
|
|
843
|
-
importSource: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
844
|
-
/**
|
|
845
|
-
* The identifier that's used for JSX Element creation.
|
|
846
|
-
* @default `"createElement"`
|
|
847
|
-
* @deprecated
|
|
848
|
-
*/
|
|
849
|
-
jsxPragma: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
850
|
-
/**
|
|
851
|
-
* The identifier that's used for JSX fragment elements.
|
|
852
|
-
* @description This should not be a member expression (i.e. use "Fragment" instead of "React.Fragment").
|
|
853
|
-
* @default `"Fragment"`
|
|
854
|
-
* @deprecated
|
|
855
|
-
*/
|
|
856
|
-
jsxPragmaFrag: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
857
|
-
/**
|
|
858
|
-
* The name of the prop that is used for polymorphic components.
|
|
859
|
-
* @description This is used to determine the type of the component.
|
|
860
|
-
* @example `"as"`
|
|
861
|
-
*/
|
|
862
|
-
polymorphicPropName: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
863
|
-
/**
|
|
864
|
-
* @default `true`
|
|
865
|
-
* @internal
|
|
866
|
-
*/
|
|
867
|
-
strict: z.ZodMiniOptional<z.ZodMiniBoolean<boolean>>;
|
|
868
|
-
/**
|
|
869
|
-
* Check both the shape and the import to determine if an API is from React.
|
|
870
|
-
* @default `true`
|
|
871
|
-
* @internal
|
|
872
|
-
*/
|
|
873
|
-
skipImportCheck: z.ZodMiniOptional<z.ZodMiniBoolean<boolean>>;
|
|
874
|
-
/**
|
|
875
|
-
* React version to use, "detect" means auto detect React version from the project's dependencies.
|
|
876
|
-
* If `importSource` is specified, an equivalent version of React should be provided here.
|
|
877
|
-
* @example `"18.3.1"`
|
|
878
|
-
* @default `"detect"`
|
|
879
|
-
*/
|
|
880
|
-
version: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
881
|
-
/**
|
|
882
|
-
* A object to define additional hooks that are equivalent to the built-in React Hooks.
|
|
883
|
-
* @description ESLint React will recognize these aliases as equivalent to the built-in hooks in all its rules.
|
|
884
|
-
* @example `{ useEffect: ["useIsomorphicLayoutEffect"] }`
|
|
885
|
-
*/
|
|
886
|
-
additionalHooks: z.ZodMiniOptional<z.ZodMiniObject<{
|
|
887
|
-
use: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
|
|
888
|
-
useActionState: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
|
|
889
|
-
useCallback: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
|
|
890
|
-
useContext: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
|
|
891
|
-
useDebugValue: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
|
|
892
|
-
useDeferredValue: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
|
|
893
|
-
useEffect: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
|
|
894
|
-
useFormStatus: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
|
|
895
|
-
useId: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
|
|
896
|
-
useImperativeHandle: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
|
|
897
|
-
useInsertionEffect: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
|
|
898
|
-
useLayoutEffect: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
|
|
899
|
-
useMemo: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
|
|
900
|
-
useOptimistic: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
|
|
901
|
-
useReducer: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
|
|
902
|
-
useRef: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
|
|
903
|
-
useState: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
|
|
904
|
-
useSyncExternalStore: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
|
|
905
|
-
useTransition: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniString<string>>>;
|
|
906
|
-
}, {}>>;
|
|
907
|
-
/**
|
|
908
|
-
* An array of user-defined components
|
|
909
|
-
* @description This is used to inform the ESLint React plugins how to treat these components during checks.
|
|
910
|
-
* @example `[{ name: "Link", as: "a", attributes: [{ name: "to", as: "href" }, { name: "rel", defaultValue: "noopener noreferrer" }] }]`
|
|
911
|
-
*/
|
|
912
|
-
additionalComponents: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniObject<{
|
|
913
|
-
/**
|
|
914
|
-
* The name of the user-defined component.
|
|
915
|
-
* @example
|
|
916
|
-
* "Link"
|
|
917
|
-
*/
|
|
918
|
-
name: z.ZodMiniString<string>;
|
|
919
|
-
/**
|
|
920
|
-
* The name of the host component that the user-defined component represents.
|
|
921
|
-
* @example
|
|
922
|
-
* "a"
|
|
923
|
-
*/
|
|
924
|
-
as: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
925
|
-
/**
|
|
926
|
-
* Attributes mapping between the user-defined component and the host component.
|
|
927
|
-
* @example
|
|
928
|
-
* `Link` component has a `to` attribute that represents the `href` attribute in the built-in `a` element with a default value of `"/"`.
|
|
929
|
-
*/
|
|
930
|
-
attributes: z.ZodMiniOptional<z.ZodMiniArray<z.ZodMiniObject<{
|
|
931
|
-
/**
|
|
932
|
-
* The name of the prop in the user-defined component.
|
|
933
|
-
* @example
|
|
934
|
-
* "to"
|
|
935
|
-
*/
|
|
936
|
-
name: z.ZodMiniString<string>;
|
|
937
|
-
/**
|
|
938
|
-
* The name of the prop in the host component.
|
|
939
|
-
* @example
|
|
940
|
-
* "href"
|
|
941
|
-
*/
|
|
942
|
-
as: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
943
|
-
/**
|
|
944
|
-
* Whether the prop is controlled or not in the user-defined component.
|
|
945
|
-
* @internal
|
|
946
|
-
* @example
|
|
947
|
-
* `true`
|
|
948
|
-
*/
|
|
949
|
-
controlled: z.ZodMiniOptional<z.ZodMiniBoolean<boolean>>;
|
|
950
|
-
/**
|
|
951
|
-
* The default value of the prop in the user-defined component.
|
|
952
|
-
* @example
|
|
953
|
-
* `"/"`
|
|
954
|
-
*/
|
|
955
|
-
defaultValue: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
956
|
-
}, {}>>>;
|
|
957
|
-
/**
|
|
958
|
-
* The ESQuery selector to select the component precisely.
|
|
959
|
-
* @internal
|
|
960
|
-
* @example
|
|
961
|
-
* `JSXElement:has(JSXAttribute[name.name='component'][value.value='a'])`
|
|
962
|
-
*/
|
|
963
|
-
selector: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
964
|
-
}, {}>>>;
|
|
965
|
-
}, {}>;
|
|
68
|
+
declare const ESLintReactSettingsSchema: z.ZodObject<{
|
|
69
|
+
importSource: z.ZodOptional<z.ZodString>;
|
|
70
|
+
polymorphicPropName: z.ZodOptional<z.ZodString>;
|
|
71
|
+
version: z.ZodOptional<z.ZodString>;
|
|
72
|
+
}, z.core.$strip>;
|
|
966
73
|
/**
|
|
74
|
+
* Schema for ESLint settings
|
|
967
75
|
* @internal
|
|
968
76
|
*/
|
|
969
|
-
declare const ESLintSettingsSchema: z.
|
|
970
|
-
|
|
971
|
-
},
|
|
972
|
-
type CustomComponent = z.infer<typeof CustomComponentSchema>;
|
|
973
|
-
type CustomComponentProp = z.infer<typeof CustomComponentPropSchema>;
|
|
974
|
-
type CustomHooks = z.infer<typeof CustomHooksSchema>;
|
|
77
|
+
declare const ESLintSettingsSchema: z.ZodOptional<z.ZodObject<{
|
|
78
|
+
"react-x": z.ZodOptional<z.ZodUnknown>;
|
|
79
|
+
}, z.core.$strip>>;
|
|
975
80
|
type ESLintSettings = z.infer<typeof ESLintSettingsSchema>;
|
|
976
81
|
type ESLintReactSettings = z.infer<typeof ESLintReactSettingsSchema>;
|
|
977
|
-
declare function isESLintSettings(settings: unknown): settings is ESLintSettings;
|
|
978
|
-
declare function isESLintReactSettings(settings: unknown): settings is ESLintReactSettings;
|
|
979
82
|
/**
|
|
980
|
-
*
|
|
83
|
+
* Normalized ESLint React settings with processed values
|
|
84
|
+
*/
|
|
85
|
+
interface ESLintReactSettingsNormalized {
|
|
86
|
+
importSource: string;
|
|
87
|
+
polymorphicPropName: string | unit;
|
|
88
|
+
version: string;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Default ESLint React settings
|
|
981
92
|
*/
|
|
982
93
|
declare const DEFAULT_ESLINT_REACT_SETTINGS: {
|
|
94
|
+
readonly version: "detect";
|
|
95
|
+
readonly importSource: "react";
|
|
96
|
+
readonly polymorphicPropName: "as";
|
|
97
|
+
};
|
|
98
|
+
/**
|
|
99
|
+
* Default ESLint settings with React settings included
|
|
100
|
+
*/
|
|
101
|
+
declare const DEFAULT_ESLINT_SETTINGS: {
|
|
102
|
+
readonly "react-x": {
|
|
983
103
|
readonly version: "detect";
|
|
984
104
|
readonly importSource: "react";
|
|
985
|
-
readonly strict: true;
|
|
986
|
-
readonly skipImportCheck: true;
|
|
987
105
|
readonly polymorphicPropName: "as";
|
|
988
|
-
|
|
989
|
-
readonly additionalHooks: {
|
|
990
|
-
readonly useEffect: ["useIsomorphicLayoutEffect"];
|
|
991
|
-
readonly useLayoutEffect: ["useIsomorphicLayoutEffect"];
|
|
992
|
-
};
|
|
993
|
-
};
|
|
994
|
-
declare const DEFAULT_ESLINT_SETTINGS: {
|
|
995
|
-
readonly "react-x": {
|
|
996
|
-
readonly version: "detect";
|
|
997
|
-
readonly importSource: "react";
|
|
998
|
-
readonly strict: true;
|
|
999
|
-
readonly skipImportCheck: true;
|
|
1000
|
-
readonly polymorphicPropName: "as";
|
|
1001
|
-
readonly additionalComponents: [];
|
|
1002
|
-
readonly additionalHooks: {
|
|
1003
|
-
readonly useEffect: ["useIsomorphicLayoutEffect"];
|
|
1004
|
-
readonly useLayoutEffect: ["useIsomorphicLayoutEffect"];
|
|
1005
|
-
};
|
|
1006
|
-
};
|
|
106
|
+
};
|
|
1007
107
|
};
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
additionalHooks: CustomHooks;
|
|
1023
|
-
components: CustomComponentNormalized[];
|
|
1024
|
-
importSource: string;
|
|
1025
|
-
polymorphicPropName: string | _;
|
|
1026
|
-
skipImportCheck: boolean;
|
|
1027
|
-
strict: boolean;
|
|
1028
|
-
version: string;
|
|
1029
|
-
}
|
|
108
|
+
/**
|
|
109
|
+
* Checks if the provided settings conform to ESLintSettings schema
|
|
110
|
+
* @param settings The settings object to validate
|
|
111
|
+
*/
|
|
112
|
+
declare function isESLintSettings(settings: unknown): settings is ESLintSettings;
|
|
113
|
+
/**
|
|
114
|
+
* Checks if the provided settings conform to ESLintReactSettings schema
|
|
115
|
+
* @param settings The settings object to validate
|
|
116
|
+
*/
|
|
117
|
+
declare function isESLintReactSettings(settings: unknown): settings is ESLintReactSettings;
|
|
118
|
+
/**
|
|
119
|
+
* Coerces unknown input to ESLintSettings type
|
|
120
|
+
* @param settings The settings object to coerce
|
|
121
|
+
*/
|
|
1030
122
|
declare const coerceESLintSettings: (settings: unknown) => PartialDeep<ESLintSettings>;
|
|
123
|
+
/**
|
|
124
|
+
* Decodes and validates ESLint settings, using defaults if invalid
|
|
125
|
+
* @param settings The settings object to decode
|
|
126
|
+
*/
|
|
1031
127
|
declare const decodeESLintSettings: (settings: unknown) => ESLintSettings;
|
|
128
|
+
/**
|
|
129
|
+
* Coerces unknown input to ESLintReactSettings type
|
|
130
|
+
* @param settings The settings object to coerce
|
|
131
|
+
*/
|
|
1032
132
|
declare const coerceSettings: (settings: unknown) => PartialDeep<ESLintReactSettings>;
|
|
133
|
+
/**
|
|
134
|
+
* Decodes and validates ESLint React settings, using defaults if invalid
|
|
135
|
+
* @param settings The settings object to decode
|
|
136
|
+
*/
|
|
1033
137
|
declare const decodeSettings: (settings: unknown) => ESLintReactSettings;
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
useContext?: string[] | undefined;
|
|
1054
|
-
useDebugValue?: string[] | undefined;
|
|
1055
|
-
useDeferredValue?: string[] | undefined;
|
|
1056
|
-
useEffect?: string[] | undefined;
|
|
1057
|
-
useFormStatus?: string[] | undefined;
|
|
1058
|
-
useId?: string[] | undefined;
|
|
1059
|
-
useImperativeHandle?: string[] | undefined;
|
|
1060
|
-
useInsertionEffect?: string[] | undefined;
|
|
1061
|
-
useLayoutEffect?: string[] | undefined;
|
|
1062
|
-
useMemo?: string[] | undefined;
|
|
1063
|
-
useOptimistic?: string[] | undefined;
|
|
1064
|
-
useReducer?: string[] | undefined;
|
|
1065
|
-
useRef?: string[] | undefined;
|
|
1066
|
-
useState?: string[] | undefined;
|
|
1067
|
-
useSyncExternalStore?: string[] | undefined;
|
|
1068
|
-
useTransition?: string[] | undefined;
|
|
1069
|
-
};
|
|
1070
|
-
readonly importSource: string;
|
|
1071
|
-
readonly polymorphicPropName: string;
|
|
1072
|
-
readonly skipImportCheck: boolean;
|
|
1073
|
-
readonly strict: boolean;
|
|
1074
|
-
readonly version: string;
|
|
1075
|
-
readonly jsxPragma?: string | undefined;
|
|
1076
|
-
readonly jsxPragmaFrag?: string | undefined;
|
|
1077
|
-
};
|
|
138
|
+
/**
|
|
139
|
+
* Normalizes ESLint React settings to a consistent internal format
|
|
140
|
+
* Transforms component definitions and resolves version information
|
|
141
|
+
*/
|
|
142
|
+
declare const normalizeSettings: ({
|
|
143
|
+
importSource,
|
|
144
|
+
polymorphicPropName,
|
|
145
|
+
version,
|
|
146
|
+
...rest
|
|
147
|
+
}: ESLintReactSettings) => {
|
|
148
|
+
readonly importSource: string;
|
|
149
|
+
readonly polymorphicPropName: string;
|
|
150
|
+
readonly version: string;
|
|
151
|
+
};
|
|
152
|
+
/**
|
|
153
|
+
* Retrieves normalized ESLint React settings from the rule context
|
|
154
|
+
* Uses caching for performance optimization
|
|
155
|
+
* @param context The ESLint rule context
|
|
156
|
+
*/
|
|
1078
157
|
declare function getSettingsFromContext(context: RuleContext): ESLintReactSettingsNormalized;
|
|
1079
158
|
/**
|
|
1080
|
-
*
|
|
1081
|
-
*
|
|
1082
|
-
* @returns The settings.
|
|
159
|
+
* Helper function for defining typed settings for "react-x" in JavaScript files
|
|
160
|
+
* Provides type checking without runtime transformation
|
|
1083
161
|
*/
|
|
1084
162
|
declare const defineSettings: (settings: ESLintReactSettings) => ESLintReactSettings;
|
|
1085
163
|
declare module "@typescript-eslint/utils/ts-eslint" {
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
164
|
+
interface SharedConfigurationSettings {
|
|
165
|
+
["react-x"]?: Partial<ESLintReactSettings>;
|
|
166
|
+
}
|
|
1089
167
|
}
|
|
1090
|
-
|
|
1091
|
-
export {
|
|
168
|
+
//#endregion
|
|
169
|
+
export { DEFAULT_ESLINT_REACT_SETTINGS, DEFAULT_ESLINT_SETTINGS, ESLintReactSettings, ESLintReactSettingsNormalized, ESLintReactSettingsSchema, ESLintSettings, ESLintSettingsSchema, GITHUB_URL, NPM_SCOPE, WEBSITE_URL, _require, coerceESLintSettings, coerceSettings, decodeESLintSettings, decodeSettings, defineSettings, getConfigAdapters, getDocsUrl, getId, getReactVersion, getSettingsFromContext, isESLintReactSettings, isESLintSettings, normalizeSettings };
|