forked from recharts/recharts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypes.d.ts
More file actions
48 lines (46 loc) · 1.92 KB
/
types.d.ts
File metadata and controls
48 lines (46 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
interface Array<T> {
/**
* Filters out null and undefined values from an array.
* This override provides a more specific return type when Boolean is used as the predicate.
*
* This is necessary because the default TypeScript definition for `Array.prototype.filter`
* does not account for the fact that when using `Boolean` as the predicate,
* the return type should be an array of non-nullable values.
*
* @example
* const arr = [1, null, 2, undefined, 3];
* const filtered = arr.filter(Boolean); // filtered is of type number[]
*/
filter(predicate: BooleanConstructor): Array<NonNullable<T>>;
}
interface ReadonlyArray<T> {
/**
* Filters out null and undefined values from a readonly array.
* This override provides a more specific return type when Boolean is used as the predicate.
*
* This is necessary because the default TypeScript definition for `ReadonlyArray.prototype.filter`
* does not account for the fact that when using `Boolean` as the predicate,
* the return type should be an array of non-nullable values.
*
* @example
* const arr: ReadonlyArray<number | null> = [1, null, 2, undefined, 3];
* const filtered = arr.filter(Boolean); // filtered is of type ReadonlyArray<number>
*/
filter(predicate: BooleanConstructor): ReadonlyArray<NonNullable<T>>;
}
interface ArrayConstructor {
/**
* The vanilla definition casts ReadonlyArray to any[] which hides type problems.
* Workaround for https://github.com/Microsoft/TypeScript/issues/17002
*
* This variant is stricter than necessary to keep the type readable.
* It will decide that all arrays are read-only arrays, which is not 100% correct,
* but in practice it should be good enough.
*
* If you need to mutate an array - don't.
* If you must - then don't run it through Array.isArray first.
*
* @param arg
*/
isArray(arg: ReadonlyArray<any> | any): arg is ReadonlyArray<unknown>;
}