@eslint-react/shared 2.0.0-next.58 → 2.0.0-next.61
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 +239 -841
- package/dist/index.js +233 -220
- package/package.json +9 -10
package/dist/index.d.ts
CHANGED
|
@@ -1,17 +1,22 @@
|
|
|
1
|
-
import { unit } from
|
|
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,721 +56,71 @@ 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
|
-
|
|
62
|
+
//#endregion
|
|
63
|
+
//#region src/settings.d.ts
|
|
620
64
|
/**
|
|
621
|
-
|
|
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
|
-
|
|
65
|
+
* Schema for component prop mapping between user-defined components and host components
|
|
66
|
+
*/
|
|
726
67
|
declare const CustomComponentPropSchema: z.ZodObject<{
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
68
|
+
name: z.ZodString;
|
|
69
|
+
as: z.ZodOptional<z.ZodString>;
|
|
70
|
+
controlled: z.ZodOptional<z.ZodBoolean>;
|
|
71
|
+
defaultValue: z.ZodOptional<z.ZodString>;
|
|
731
72
|
}, z.core.$strip>;
|
|
732
73
|
/**
|
|
733
|
-
*
|
|
734
|
-
*
|
|
735
|
-
*
|
|
736
|
-
* Which prop is used as the `href` prop for the user-defined `Link` component that represents the built-in `a` element.
|
|
74
|
+
* Schema for custom components configuration
|
|
75
|
+
* Provides key information about user-defined components before validation
|
|
76
|
+
* Example: Which prop is used as the `href` prop in a custom `Link` component
|
|
737
77
|
*/
|
|
738
78
|
declare const CustomComponentSchema: z.ZodObject<{
|
|
79
|
+
name: z.ZodString;
|
|
80
|
+
as: z.ZodOptional<z.ZodString>;
|
|
81
|
+
attributes: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
739
82
|
name: z.ZodString;
|
|
740
83
|
as: z.ZodOptional<z.ZodString>;
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
defaultValue: z.ZodOptional<z.ZodString>;
|
|
746
|
-
}, z.core.$strip>>>;
|
|
747
|
-
selector: z.ZodOptional<z.ZodString>;
|
|
84
|
+
controlled: z.ZodOptional<z.ZodBoolean>;
|
|
85
|
+
defaultValue: z.ZodOptional<z.ZodString>;
|
|
86
|
+
}, z.core.$strip>>>;
|
|
87
|
+
selector: z.ZodOptional<z.ZodString>;
|
|
748
88
|
}, z.core.$strip>;
|
|
89
|
+
/**
|
|
90
|
+
* Schema for custom hooks aliases that should be treated as React Hooks
|
|
91
|
+
*/
|
|
749
92
|
declare const CustomHooksSchema: z.ZodObject<{
|
|
93
|
+
use: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
94
|
+
useActionState: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
95
|
+
useCallback: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
96
|
+
useContext: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
97
|
+
useDebugValue: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
98
|
+
useDeferredValue: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
99
|
+
useEffect: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
100
|
+
useFormStatus: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
101
|
+
useId: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
102
|
+
useImperativeHandle: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
103
|
+
useInsertionEffect: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
104
|
+
useLayoutEffect: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
105
|
+
useMemo: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
106
|
+
useOptimistic: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
107
|
+
useReducer: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
108
|
+
useRef: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
109
|
+
useState: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
110
|
+
useSyncExternalStore: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
111
|
+
useTransition: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
112
|
+
}, z.core.$strip>;
|
|
113
|
+
/**
|
|
114
|
+
* Schema for ESLint React settings configuration
|
|
115
|
+
* @internal
|
|
116
|
+
*/
|
|
117
|
+
declare const ESLintReactSettingsSchema: z.ZodObject<{
|
|
118
|
+
importSource: z.ZodOptional<z.ZodString>;
|
|
119
|
+
polymorphicPropName: z.ZodOptional<z.ZodString>;
|
|
120
|
+
strict: z.ZodOptional<z.ZodBoolean>;
|
|
121
|
+
skipImportCheck: z.ZodOptional<z.ZodBoolean>;
|
|
122
|
+
version: z.ZodOptional<z.ZodString>;
|
|
123
|
+
additionalHooks: z.ZodOptional<z.ZodObject<{
|
|
750
124
|
use: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
751
125
|
useActionState: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
752
126
|
useCallback: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
@@ -766,66 +140,82 @@ declare const CustomHooksSchema: z.ZodObject<{
|
|
|
766
140
|
useState: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
767
141
|
useSyncExternalStore: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
768
142
|
useTransition: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
769
|
-
}, z.core.$strip
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
version: z.ZodOptional<z.ZodString>;
|
|
779
|
-
additionalHooks: z.ZodOptional<z.ZodObject<{
|
|
780
|
-
use: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
781
|
-
useActionState: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
782
|
-
useCallback: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
783
|
-
useContext: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
784
|
-
useDebugValue: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
785
|
-
useDeferredValue: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
786
|
-
useEffect: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
787
|
-
useFormStatus: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
788
|
-
useId: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
789
|
-
useImperativeHandle: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
790
|
-
useInsertionEffect: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
791
|
-
useLayoutEffect: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
792
|
-
useMemo: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
793
|
-
useOptimistic: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
794
|
-
useReducer: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
795
|
-
useRef: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
796
|
-
useState: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
797
|
-
useSyncExternalStore: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
798
|
-
useTransition: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
799
|
-
}, z.core.$strip>>;
|
|
800
|
-
additionalComponents: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
801
|
-
name: z.ZodString;
|
|
802
|
-
as: z.ZodOptional<z.ZodString>;
|
|
803
|
-
attributes: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
804
|
-
name: z.ZodString;
|
|
805
|
-
as: z.ZodOptional<z.ZodString>;
|
|
806
|
-
controlled: z.ZodOptional<z.ZodBoolean>;
|
|
807
|
-
defaultValue: z.ZodOptional<z.ZodString>;
|
|
808
|
-
}, z.core.$strip>>>;
|
|
809
|
-
selector: z.ZodOptional<z.ZodString>;
|
|
143
|
+
}, z.core.$strip>>;
|
|
144
|
+
additionalComponents: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
145
|
+
name: z.ZodString;
|
|
146
|
+
as: z.ZodOptional<z.ZodString>;
|
|
147
|
+
attributes: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
148
|
+
name: z.ZodString;
|
|
149
|
+
as: z.ZodOptional<z.ZodString>;
|
|
150
|
+
controlled: z.ZodOptional<z.ZodBoolean>;
|
|
151
|
+
defaultValue: z.ZodOptional<z.ZodString>;
|
|
810
152
|
}, z.core.$strip>>>;
|
|
153
|
+
selector: z.ZodOptional<z.ZodString>;
|
|
154
|
+
}, z.core.$strip>>>;
|
|
811
155
|
}, z.core.$strip>;
|
|
812
156
|
/**
|
|
157
|
+
* Schema for ESLint settings
|
|
813
158
|
* @internal
|
|
814
159
|
*/
|
|
815
160
|
declare const ESLintSettingsSchema: z.ZodOptional<z.ZodObject<{
|
|
816
|
-
|
|
161
|
+
"react-x": z.ZodOptional<z.ZodUnknown>;
|
|
817
162
|
}, z.core.$strip>>;
|
|
818
163
|
type CustomComponent = z.infer<typeof CustomComponentSchema>;
|
|
819
164
|
type CustomComponentProp = z.infer<typeof CustomComponentPropSchema>;
|
|
820
165
|
type CustomHooks = z.infer<typeof CustomHooksSchema>;
|
|
821
166
|
type ESLintSettings = z.infer<typeof ESLintSettingsSchema>;
|
|
822
167
|
type ESLintReactSettings = z.infer<typeof ESLintReactSettingsSchema>;
|
|
823
|
-
declare function isESLintSettings(settings: unknown): settings is ESLintSettings;
|
|
824
|
-
declare function isESLintReactSettings(settings: unknown): settings is ESLintReactSettings;
|
|
825
168
|
/**
|
|
826
|
-
*
|
|
169
|
+
* Normalized representation of a custom component prop
|
|
170
|
+
*/
|
|
171
|
+
interface CustomComponentPropNormalized {
|
|
172
|
+
name: string;
|
|
173
|
+
as: string;
|
|
174
|
+
defaultValue?: string | unit;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Normalized representation of a custom component with RegExp for matching
|
|
178
|
+
*/
|
|
179
|
+
interface CustomComponentNormalized {
|
|
180
|
+
name: string;
|
|
181
|
+
as: string;
|
|
182
|
+
attributes: CustomComponentPropNormalized[];
|
|
183
|
+
re: {
|
|
184
|
+
test(s: string): boolean;
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Normalized ESLint React settings with processed values
|
|
189
|
+
*/
|
|
190
|
+
interface ESLintReactSettingsNormalized {
|
|
191
|
+
additionalHooks: CustomHooks;
|
|
192
|
+
components: CustomComponentNormalized[];
|
|
193
|
+
importSource: string;
|
|
194
|
+
polymorphicPropName: string | unit;
|
|
195
|
+
skipImportCheck: boolean;
|
|
196
|
+
strict: boolean;
|
|
197
|
+
version: string;
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Default ESLint React settings
|
|
827
201
|
*/
|
|
828
202
|
declare const DEFAULT_ESLINT_REACT_SETTINGS: {
|
|
203
|
+
readonly version: "detect";
|
|
204
|
+
readonly importSource: "react";
|
|
205
|
+
readonly strict: true;
|
|
206
|
+
readonly skipImportCheck: true;
|
|
207
|
+
readonly polymorphicPropName: "as";
|
|
208
|
+
readonly additionalComponents: [];
|
|
209
|
+
readonly additionalHooks: {
|
|
210
|
+
readonly useEffect: ["useIsomorphicLayoutEffect"];
|
|
211
|
+
readonly useLayoutEffect: ["useIsomorphicLayoutEffect"];
|
|
212
|
+
};
|
|
213
|
+
};
|
|
214
|
+
/**
|
|
215
|
+
* Default ESLint settings with React settings included
|
|
216
|
+
*/
|
|
217
|
+
declare const DEFAULT_ESLINT_SETTINGS: {
|
|
218
|
+
readonly "react-x": {
|
|
829
219
|
readonly version: "detect";
|
|
830
220
|
readonly importSource: "react";
|
|
831
221
|
readonly strict: true;
|
|
@@ -833,103 +223,111 @@ declare const DEFAULT_ESLINT_REACT_SETTINGS: {
|
|
|
833
223
|
readonly polymorphicPropName: "as";
|
|
834
224
|
readonly additionalComponents: [];
|
|
835
225
|
readonly additionalHooks: {
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
};
|
|
839
|
-
};
|
|
840
|
-
declare const DEFAULT_ESLINT_SETTINGS: {
|
|
841
|
-
readonly "react-x": {
|
|
842
|
-
readonly version: "detect";
|
|
843
|
-
readonly importSource: "react";
|
|
844
|
-
readonly strict: true;
|
|
845
|
-
readonly skipImportCheck: true;
|
|
846
|
-
readonly polymorphicPropName: "as";
|
|
847
|
-
readonly additionalComponents: [];
|
|
848
|
-
readonly additionalHooks: {
|
|
849
|
-
readonly useEffect: ["useIsomorphicLayoutEffect"];
|
|
850
|
-
readonly useLayoutEffect: ["useIsomorphicLayoutEffect"];
|
|
851
|
-
};
|
|
226
|
+
readonly useEffect: ["useIsomorphicLayoutEffect"];
|
|
227
|
+
readonly useLayoutEffect: ["useIsomorphicLayoutEffect"];
|
|
852
228
|
};
|
|
229
|
+
};
|
|
853
230
|
};
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
additionalHooks: CustomHooks;
|
|
869
|
-
components: CustomComponentNormalized[];
|
|
870
|
-
importSource: string;
|
|
871
|
-
polymorphicPropName: string | unit;
|
|
872
|
-
skipImportCheck: boolean;
|
|
873
|
-
strict: boolean;
|
|
874
|
-
version: string;
|
|
875
|
-
}
|
|
231
|
+
/**
|
|
232
|
+
* Checks if the provided settings conform to ESLintSettings schema
|
|
233
|
+
* @param settings The settings object to validate
|
|
234
|
+
*/
|
|
235
|
+
declare function isESLintSettings(settings: unknown): settings is ESLintSettings;
|
|
236
|
+
/**
|
|
237
|
+
* Checks if the provided settings conform to ESLintReactSettings schema
|
|
238
|
+
* @param settings The settings object to validate
|
|
239
|
+
*/
|
|
240
|
+
declare function isESLintReactSettings(settings: unknown): settings is ESLintReactSettings;
|
|
241
|
+
/**
|
|
242
|
+
* Coerces unknown input to ESLintSettings type
|
|
243
|
+
* @param settings The settings object to coerce
|
|
244
|
+
*/
|
|
876
245
|
declare const coerceESLintSettings: (settings: unknown) => PartialDeep<ESLintSettings>;
|
|
246
|
+
/**
|
|
247
|
+
* Decodes and validates ESLint settings, using defaults if invalid
|
|
248
|
+
* @param settings The settings object to decode
|
|
249
|
+
*/
|
|
877
250
|
declare const decodeESLintSettings: (settings: unknown) => ESLintSettings;
|
|
251
|
+
/**
|
|
252
|
+
* Coerces unknown input to ESLintReactSettings type
|
|
253
|
+
* @param settings The settings object to coerce
|
|
254
|
+
*/
|
|
878
255
|
declare const coerceSettings: (settings: unknown) => PartialDeep<ESLintReactSettings>;
|
|
256
|
+
/**
|
|
257
|
+
* Decodes and validates ESLint React settings, using defaults if invalid
|
|
258
|
+
* @param settings The settings object to decode
|
|
259
|
+
*/
|
|
879
260
|
declare const decodeSettings: (settings: unknown) => ESLintReactSettings;
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
useCallback?: string[] | undefined;
|
|
899
|
-
useContext?: string[] | undefined;
|
|
900
|
-
useDebugValue?: string[] | undefined;
|
|
901
|
-
useDeferredValue?: string[] | undefined;
|
|
902
|
-
useEffect?: string[] | undefined;
|
|
903
|
-
useFormStatus?: string[] | undefined;
|
|
904
|
-
useId?: string[] | undefined;
|
|
905
|
-
useImperativeHandle?: string[] | undefined;
|
|
906
|
-
useInsertionEffect?: string[] | undefined;
|
|
907
|
-
useLayoutEffect?: string[] | undefined;
|
|
908
|
-
useMemo?: string[] | undefined;
|
|
909
|
-
useOptimistic?: string[] | undefined;
|
|
910
|
-
useReducer?: string[] | undefined;
|
|
911
|
-
useRef?: string[] | undefined;
|
|
912
|
-
useState?: string[] | undefined;
|
|
913
|
-
useSyncExternalStore?: string[] | undefined;
|
|
914
|
-
useTransition?: string[] | undefined;
|
|
261
|
+
/**
|
|
262
|
+
* Normalizes ESLint React settings to a consistent internal format
|
|
263
|
+
* Transforms component definitions and resolves version information
|
|
264
|
+
*/
|
|
265
|
+
declare const normalizeSettings: ({
|
|
266
|
+
additionalComponents,
|
|
267
|
+
additionalHooks,
|
|
268
|
+
importSource,
|
|
269
|
+
polymorphicPropName,
|
|
270
|
+
skipImportCheck,
|
|
271
|
+
strict,
|
|
272
|
+
version,
|
|
273
|
+
...rest
|
|
274
|
+
}: ESLintReactSettings) => {
|
|
275
|
+
readonly components: {
|
|
276
|
+
name: string;
|
|
277
|
+
re: {
|
|
278
|
+
test(s: string): boolean;
|
|
915
279
|
};
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
280
|
+
as: string;
|
|
281
|
+
attributes: {
|
|
282
|
+
name: string;
|
|
283
|
+
as: string;
|
|
284
|
+
controlled?: boolean | undefined;
|
|
285
|
+
defaultValue?: string | undefined;
|
|
286
|
+
}[];
|
|
287
|
+
selector?: string | undefined;
|
|
288
|
+
}[];
|
|
289
|
+
readonly additionalHooks: {
|
|
290
|
+
use?: string[] | undefined;
|
|
291
|
+
useActionState?: string[] | undefined;
|
|
292
|
+
useCallback?: string[] | undefined;
|
|
293
|
+
useContext?: string[] | undefined;
|
|
294
|
+
useDebugValue?: string[] | undefined;
|
|
295
|
+
useDeferredValue?: string[] | undefined;
|
|
296
|
+
useEffect?: string[] | undefined;
|
|
297
|
+
useFormStatus?: string[] | undefined;
|
|
298
|
+
useId?: string[] | undefined;
|
|
299
|
+
useImperativeHandle?: string[] | undefined;
|
|
300
|
+
useInsertionEffect?: string[] | undefined;
|
|
301
|
+
useLayoutEffect?: string[] | undefined;
|
|
302
|
+
useMemo?: string[] | undefined;
|
|
303
|
+
useOptimistic?: string[] | undefined;
|
|
304
|
+
useReducer?: string[] | undefined;
|
|
305
|
+
useRef?: string[] | undefined;
|
|
306
|
+
useState?: string[] | undefined;
|
|
307
|
+
useSyncExternalStore?: string[] | undefined;
|
|
308
|
+
useTransition?: string[] | undefined;
|
|
309
|
+
};
|
|
310
|
+
readonly importSource: string;
|
|
311
|
+
readonly polymorphicPropName: string;
|
|
312
|
+
readonly skipImportCheck: boolean;
|
|
313
|
+
readonly strict: boolean;
|
|
314
|
+
readonly version: string;
|
|
921
315
|
};
|
|
316
|
+
/**
|
|
317
|
+
* Retrieves normalized ESLint React settings from the rule context
|
|
318
|
+
* Uses caching for performance optimization
|
|
319
|
+
* @param context The ESLint rule context
|
|
320
|
+
*/
|
|
922
321
|
declare function getSettingsFromContext(context: RuleContext): ESLintReactSettingsNormalized;
|
|
923
322
|
/**
|
|
924
|
-
*
|
|
925
|
-
*
|
|
926
|
-
* @returns The settings.
|
|
323
|
+
* Helper function for defining typed settings for "react-x" in JavaScript files
|
|
324
|
+
* Provides type checking without runtime transformation
|
|
927
325
|
*/
|
|
928
326
|
declare const defineSettings: (settings: ESLintReactSettings) => ESLintReactSettings;
|
|
929
327
|
declare module "@typescript-eslint/utils/ts-eslint" {
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
328
|
+
interface SharedConfigurationSettings {
|
|
329
|
+
["react-x"]?: Partial<ESLintReactSettings>;
|
|
330
|
+
}
|
|
933
331
|
}
|
|
934
|
-
|
|
935
|
-
export {
|
|
332
|
+
//#endregion
|
|
333
|
+
export { CustomComponent, CustomComponentNormalized, CustomComponentProp, CustomComponentPropNormalized, CustomComponentPropSchema, CustomComponentSchema, CustomHooks, CustomHooksSchema, 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 };
|