-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlib.es.d.ts
194 lines (160 loc) · 5.78 KB
/
lib.es.d.ts
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
import type { KeysOfUnion, Split } from 'type-fest'
import type {
AnyObject,
ExtractAndRequiredByKey,
ExtractByKey,
IterableType,
ToString
} from './utils'
type ToStringTag =
| '[object Array]'
| '[object BigInt]'
| '[object Boolean]'
| '[object Function]'
| '[object Null]'
| '[object Number]'
| '[object Object]'
| '[object String]'
| '[object Undefined]'
| (string & Record<never, never>)
// | "[object Date]"
// | "[object ArrayBuffer]"
// | "[object URL]"
declare global {
interface ObjectConstructor {
/**
* Determines whether an object has a property with the specified name.
* @param o An object.
* @param v A property name.
*/
hasOwn<T extends Record<keyof any, any>, K extends keyof globalThis.Object & KeysOfUnion<T>>(
o: T,
v: K,
): o is ExtractAndRequiredByKey<T, K>
/**
* Determines whether an object has a property with the specified name.
* @param o An object.
* @param v A property name.
*/
hasOwn(
o: Record<keyof any, any>,
v: keyof globalThis.Object,
): boolean
/**
* Determines whether an object has a property with the specified name.
* @param o An object.
* @param v A property name.
*/
hasOwn<T extends Record<keyof any, any>, K extends keyof any>(
o: T,
v: K
// @ts-expect-error FIXME: predicate type error but works
): o is K extends KeysOfUnion<T> ? ExtractAndRequiredByKey<T, K> : T & { [P in K]: unknown }
/**
* Returns an empty array
* @param o number or symbol
*/
entries(o: number | symbol | bigint): []
/**
* Returns an array of index/substring of the string
* @param s string
*/
entries(s: string): [`${number}`, string][]
/**
* Returns an array of key/values of the enumerable properties of an object
* @param o Object that contains the properties and methods. This can be an object that you created or an existing Document Object Model (DOM) object.
*/
entries<T, O extends { [k: string]: T }, K extends string = ToString<keyof O>>(o: O): [K, O[K]][]
/**
* Returns an array of key/values of the enumerable properties of an object
* @param o Object that contains the properties and methods. This can be an object that you created or an existing Document Object Model (DOM) object.
*/
entries<A extends ArrayLike<any>>(o: A): [`${number}`, A[number]][]
/**
* Returns an object created by key-value entries for properties and methods
* @param entries An iterable object that contains key-value entries for properties and methods.
*/
fromEntries<
K extends PropertyKey,
I extends Iterable<readonly [K, any]>,
T extends IterableType<I> = IterableType<I>
>(entries: I): { [Key in T[0]]: T[1] }
/**
* Returns the names of the enumerable string properties and methods of an object.
* @param o Object that contains the properties and methods. This can be an object that you created or an existing Document Object Model (DOM) object.
*/
keys<T extends AnyObject>(o: T): ToString<keyof T>[]
/**
* Returns an empty array
* @param o number or symbol
*/
keys(o: number | symbol | bigint): []
/**
* Returns index string array
* @param s string
*/
keys(s: string): `${number}`[]
/**
* Returns an empty array
* @param o number or symbol or bigint
*/
values(o: number | symbol | bigint): []
/**
* Returns an array of string split
* @param s string
*/
values<T extends string>(s: T): Split<T, ''>
}
namespace Reflect {
// `Reflect.has` will check prototype chain
// Object.create(null) has no prototype
/**
* Equivalent to `propertyKey in target`.
* @param target Object that contains the property on itself or in its prototype chain.
* @param propertyKey Name of the property.
*/
function has<T extends AnyObject>(target: T, propertyKey: keyof globalThis.Object): target is T
/**
* Equivalent to `propertyKey in target`.
* @param target Object that contains the property on itself or in its prototype chain.
* @param propertyKey Name of the property.
*/
function has<T extends AnyObject, K extends KeysOfUnion<T>>(target: T, propertyKey: K): target is ExtractByKey<T, K>
/**
* Gets the property of target, equivalent to `target[propertyKey]` when `receiver === target`.
* @param target Object that contains the property on itself or in its prototype chain.
* @param propertyKey The property name.
* @param receiver The reference to use as the `this` value in the getter function,
* if `target[propertyKey]` is an accessor property.
*/
function get<T extends object, K extends keyof T>(target: T, propertyKey: K, receiver?: any): T[K]
}
interface Object {
/** Returns a string representation of an object. */
toString(): ToStringTag
}
interface Array<T> {
/**
* Determines whether an array includes a certain element, returning true or false as appropriate.
* @param searchElement The element to search for.
*/
includes(searchElement: T): searchElement is T
includes(searchElement: any): searchElement is T
/**
* Combines two or more arrays.
* This method returns a new array without modifying any existing arrays.
* @param items Additional arrays and/or items to add to the end of the array.
*/
// concat(...items: (T)[]): T[]
// /** ggg */
// concat<K>(...items: (K | K[])[]): (T | K)[]
}
interface ArrayConstructor {
// @ts-expect-error FIXME: predicate type error but works
isArray<T>(arg: T): arg is unknown extends T // T is `unknown` or `any`
? unknown[]
: T extends readonly unknown[]
? T
: never
}
}