typenative 0.1.1 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +29 -20
- package/bin/index.js +242 -204
- package/bin/parse-native.js +3 -2
- package/bin/parse-node.js +18 -2
- package/bin/transpiler.js +2211 -113
- package/conformance.md +96 -87
- package/package.json +1 -1
- package/tsparser/main.go +53 -3
- package/tsparser/tsparser.exe +2 -2
- package/types/typenative-npm.d.ts +7 -3
- package/types/typenative.d.ts +446 -53
package/types/typenative.d.ts
CHANGED
|
@@ -1,24 +1,29 @@
|
|
|
1
|
-
// Type definitions for TypeNative
|
|
1
|
+
// Type definitions for TypeNative.
|
|
2
|
+
//
|
|
3
|
+
// Scaffolded projects compile with `lib: []` and `types: ["typenative", ...]`,
|
|
4
|
+
// so this file is the entire standard-library type surface: only declare what
|
|
5
|
+
// the transpiler actually lowers (see conformance.md for the feature matrix).
|
|
2
6
|
|
|
3
7
|
interface Boolean {}
|
|
4
8
|
|
|
5
|
-
interface CallableFunction extends Function {}
|
|
6
|
-
|
|
7
9
|
interface Function {
|
|
8
|
-
|
|
10
|
+
readonly name: string;
|
|
11
|
+
apply(thisArg: any, argArray?: any): any;
|
|
9
12
|
call(thisArg: any, ...argArray: any[]): any;
|
|
10
|
-
bind(thisArg: any, ...argArray: any[]): any; */
|
|
11
13
|
}
|
|
12
14
|
|
|
15
|
+
interface CallableFunction extends Function {}
|
|
16
|
+
interface NewableFunction extends Function {}
|
|
17
|
+
|
|
13
18
|
interface IArguments {
|
|
14
19
|
[index: number]: any;
|
|
15
20
|
length: number;
|
|
16
21
|
}
|
|
17
22
|
|
|
18
|
-
interface NewableFunction extends Function {}
|
|
19
|
-
|
|
20
23
|
interface Number {
|
|
21
|
-
toString(): string;
|
|
24
|
+
toString(radix?: number): string;
|
|
25
|
+
toFixed(fractionDigits?: number): string;
|
|
26
|
+
toPrecision(precision?: number): string;
|
|
22
27
|
}
|
|
23
28
|
|
|
24
29
|
interface Object {
|
|
@@ -26,22 +31,7 @@ interface Object {
|
|
|
26
31
|
toString(): string;
|
|
27
32
|
}
|
|
28
33
|
|
|
29
|
-
|
|
30
|
-
test(string: string): boolean;
|
|
31
|
-
exec(string: string): string[] | null;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
interface RegExpConstructor {
|
|
35
|
-
new (pattern: string, flags?: string): RegExp;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
declare var RegExp: RegExpConstructor;
|
|
39
|
-
|
|
40
|
-
interface SymbolConstructor {
|
|
41
|
-
readonly iterator: unique symbol;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
declare var Symbol: SymbolConstructor;
|
|
34
|
+
// --- Iteration protocol (also unlocks for..of / spread over Map, Set, string) ---
|
|
45
35
|
|
|
46
36
|
interface IteratorYieldResult<TYield> {
|
|
47
37
|
done?: false;
|
|
@@ -56,16 +46,107 @@ interface IteratorReturnResult<TReturn> {
|
|
|
56
46
|
type IteratorResult<T, TReturn = any> = IteratorYieldResult<T> | IteratorReturnResult<TReturn>;
|
|
57
47
|
|
|
58
48
|
interface Iterator<T, TReturn = any, TNext = any> {
|
|
59
|
-
// NOTE: 'next' is defined using a tuple to ensure we report the correct assignability errors in all places.
|
|
60
49
|
next(...[value]: [] | [TNext]): IteratorResult<T, TReturn>;
|
|
61
50
|
return?(value?: TReturn): IteratorResult<T, TReturn>;
|
|
62
51
|
throw?(e?: any): IteratorResult<T, TReturn>;
|
|
63
52
|
}
|
|
64
53
|
|
|
65
|
-
interface
|
|
54
|
+
interface Iterable<T, TReturn = any, TNext = undefined> {
|
|
55
|
+
[Symbol.iterator](): Iterator<T, TReturn, TNext>;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
interface IterableIterator<T, TReturn = any, TNext = undefined> extends Iterator<T, TReturn, TNext> {
|
|
66
59
|
[Symbol.iterator](): IterableIterator<T, TReturn, TNext>;
|
|
67
60
|
}
|
|
68
61
|
|
|
62
|
+
interface Generator<T = any, TReturn = any, TNext = any> extends Iterator<T, TReturn, TNext> {
|
|
63
|
+
[Symbol.iterator](): Generator<T, TReturn, TNext>;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
interface AsyncIterator<T, TReturn = any, TNext = any> {
|
|
67
|
+
next(...[value]: [] | [TNext]): Promise<IteratorResult<T, TReturn>>;
|
|
68
|
+
return?(value?: TReturn): Promise<IteratorResult<T, TReturn>>;
|
|
69
|
+
throw?(e?: any): Promise<IteratorResult<T, TReturn>>;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
interface AsyncIterable<T, TReturn = any, TNext = undefined> {
|
|
73
|
+
[Symbol.asyncIterator](): AsyncIterator<T, TReturn, TNext>;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
interface AsyncIterableIterator<T, TReturn = any, TNext = undefined> extends AsyncIterator<T, TReturn, TNext> {
|
|
77
|
+
[Symbol.asyncIterator](): AsyncIterableIterator<T, TReturn, TNext>;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
interface AsyncGenerator<T = any, TReturn = any, TNext = any> extends AsyncIterator<T, TReturn, TNext> {
|
|
81
|
+
[Symbol.asyncIterator](): AsyncGenerator<T, TReturn, TNext>;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// using x = r; / [Symbol.dispose]()
|
|
85
|
+
interface Disposable {
|
|
86
|
+
[Symbol.dispose](): void;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// await unwraps one thenable layer at a time
|
|
90
|
+
type Awaited<T> = T extends null | undefined
|
|
91
|
+
? T
|
|
92
|
+
: T extends { then(onfulfilled: (value: infer U) => any): any }
|
|
93
|
+
? Awaited<U>
|
|
94
|
+
: T;
|
|
95
|
+
|
|
96
|
+
// Tagged template functions: tag`a${x}b`
|
|
97
|
+
interface TemplateStringsArray {
|
|
98
|
+
readonly [index: number]: string;
|
|
99
|
+
readonly length: number;
|
|
100
|
+
readonly raw: readonly string[];
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// Array.from(arrayLike, mapFn)
|
|
104
|
+
interface ArrayLike<T> {
|
|
105
|
+
length: number;
|
|
106
|
+
[n: number]: T;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// --- Utility types (lowered to the Go type of their first argument) ---
|
|
110
|
+
|
|
111
|
+
type Partial<T> = { [P in keyof T]?: T[P] };
|
|
112
|
+
type Required<T> = { [P in keyof T]-?: T[P] };
|
|
113
|
+
type Readonly<T> = { readonly [P in keyof T]: T[P] };
|
|
114
|
+
type Pick<T, K extends keyof T> = { [P in K]: T[P] };
|
|
115
|
+
type Omit<T, K extends keyof any> = { [P in keyof T as P extends K ? never : P]: T[P] };
|
|
116
|
+
type NonNullable<T> = T & {};
|
|
117
|
+
type Record<K extends keyof any, T> = { [P in K]: T };
|
|
118
|
+
|
|
119
|
+
// --- RegExp ---
|
|
120
|
+
|
|
121
|
+
interface RegExp {
|
|
122
|
+
lastIndex: number;
|
|
123
|
+
readonly source: string;
|
|
124
|
+
readonly flags: string;
|
|
125
|
+
readonly global: boolean;
|
|
126
|
+
readonly ignoreCase: boolean;
|
|
127
|
+
readonly multiline: boolean;
|
|
128
|
+
readonly dotAll: boolean;
|
|
129
|
+
readonly unicode: boolean;
|
|
130
|
+
readonly sticky: boolean;
|
|
131
|
+
test(string: string): boolean;
|
|
132
|
+
exec(string: string): RegExpExecArray | null;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// exec() result; named-group regexes carry a .groups record
|
|
136
|
+
interface RegExpExecArray extends Array<string> {
|
|
137
|
+
index: number;
|
|
138
|
+
readonly groups: Record<string, string> | undefined;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
interface RegExpConstructor {
|
|
142
|
+
new (pattern: string | RegExp, flags?: string): RegExp;
|
|
143
|
+
(pattern: string | RegExp, flags?: string): RegExp;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
declare var RegExp: RegExpConstructor;
|
|
147
|
+
|
|
148
|
+
// --- Array ---
|
|
149
|
+
|
|
69
150
|
interface Array<T> extends IterableIterator<T> {
|
|
70
151
|
/**
|
|
71
152
|
* Gets or sets the length of the array. This is a number one higher than the highest index in the array.
|
|
@@ -74,7 +155,7 @@ interface Array<T> extends IterableIterator<T> {
|
|
|
74
155
|
/**
|
|
75
156
|
* Appends new elements to the end of an array.
|
|
76
157
|
*/
|
|
77
|
-
push(
|
|
158
|
+
push(...items: T[]): number;
|
|
78
159
|
/**
|
|
79
160
|
* Adds all the elements of an array into a string, separated by the specified separator string.
|
|
80
161
|
*/
|
|
@@ -103,6 +184,14 @@ interface Array<T> extends IterableIterator<T> {
|
|
|
103
184
|
* Returns the index of the first element that satisfies the callback, or -1.
|
|
104
185
|
*/
|
|
105
186
|
findIndex(callback: (value: T, index?: number, array?: T[]) => boolean): number;
|
|
187
|
+
/**
|
|
188
|
+
* Returns the value of the last element where callback is true, and undefined otherwise.
|
|
189
|
+
*/
|
|
190
|
+
findLast(callback: (value: T, index?: number, array?: T[]) => boolean): T | undefined;
|
|
191
|
+
/**
|
|
192
|
+
* Returns the index of the last element that satisfies the callback, or -1.
|
|
193
|
+
*/
|
|
194
|
+
findLastIndex(callback: (value: T, index?: number, array?: T[]) => boolean): number;
|
|
106
195
|
/**
|
|
107
196
|
* Determines whether all elements satisfy the callback.
|
|
108
197
|
*/
|
|
@@ -119,10 +208,22 @@ interface Array<T> extends IterableIterator<T> {
|
|
|
119
208
|
initialValue: U
|
|
120
209
|
): U;
|
|
121
210
|
reduce(callback: (accumulator: T, value: T, index?: number, array?: T[]) => T): T;
|
|
211
|
+
/**
|
|
212
|
+
* Calls the callback function on each element of the array in reverse order, accumulating a result.
|
|
213
|
+
*/
|
|
214
|
+
reduceRight<U>(
|
|
215
|
+
callback: (accumulator: U, value: T, index?: number, array?: T[]) => U,
|
|
216
|
+
initialValue: U
|
|
217
|
+
): U;
|
|
218
|
+
reduceRight(callback: (accumulator: T, value: T, index?: number, array?: T[]) => T): T;
|
|
122
219
|
/**
|
|
123
220
|
* Returns the index of the first occurrence of a value in an array, or -1 if it is not present.
|
|
124
221
|
*/
|
|
125
222
|
indexOf(searchElement: T): number;
|
|
223
|
+
/**
|
|
224
|
+
* Returns the index of the last occurrence of a value in an array, or -1 if it is not present.
|
|
225
|
+
*/
|
|
226
|
+
lastIndexOf(searchElement: T): number;
|
|
126
227
|
/**
|
|
127
228
|
* Determines whether an array includes a certain element.
|
|
128
229
|
*/
|
|
@@ -143,22 +244,55 @@ interface Array<T> extends IterableIterator<T> {
|
|
|
143
244
|
* Reverses the elements of an array in place.
|
|
144
245
|
*/
|
|
145
246
|
reverse(): T[];
|
|
247
|
+
/**
|
|
248
|
+
* Returns a reversed copy of the array.
|
|
249
|
+
*/
|
|
250
|
+
toReversed(): T[];
|
|
146
251
|
/**
|
|
147
252
|
* Sorts the elements of an array in place.
|
|
148
253
|
*/
|
|
149
254
|
sort(compareFn?: (a: T, b: T) => number): T[];
|
|
255
|
+
/**
|
|
256
|
+
* Returns a sorted copy of the array.
|
|
257
|
+
*/
|
|
258
|
+
toSorted(compareFn?: (a: T, b: T) => number): T[];
|
|
259
|
+
/**
|
|
260
|
+
* Removes elements from an array and, if necessary, inserts new elements in their place, returning the deleted elements.
|
|
261
|
+
*/
|
|
262
|
+
splice(start: number, deleteCount?: number, ...items: T[]): T[];
|
|
263
|
+
/**
|
|
264
|
+
* Returns a spliced copy of the array.
|
|
265
|
+
*/
|
|
266
|
+
toSpliced(start: number, deleteCount?: number, ...items: T[]): T[];
|
|
267
|
+
/**
|
|
268
|
+
* Returns a copy of the array with the element at the given index replaced.
|
|
269
|
+
*/
|
|
270
|
+
with(index: number, value: T): T[];
|
|
150
271
|
/**
|
|
151
272
|
* Returns a new array formed by applying callback to each element and then flattening.
|
|
152
273
|
*/
|
|
153
274
|
flat(): T[];
|
|
275
|
+
flatMap<U>(callback: (value: T, index?: number, array?: T[]) => U[]): U[];
|
|
276
|
+
/**
|
|
277
|
+
* Returns a copy of a section of an array with the fill value applied.
|
|
278
|
+
*/
|
|
279
|
+
fill(value: T, start?: number, end?: number): T[];
|
|
154
280
|
/**
|
|
155
|
-
*
|
|
281
|
+
* Copies within the array in place (overlap-safe) and returns it.
|
|
156
282
|
*/
|
|
157
|
-
|
|
283
|
+
copyWithin(target: number, start: number, end?: number): T[];
|
|
284
|
+
/**
|
|
285
|
+
* Merges two or more arrays (array arguments are flattened one level).
|
|
286
|
+
*/
|
|
287
|
+
concat(...items: (T | T[])[]): T[];
|
|
158
288
|
/**
|
|
159
289
|
* Returns the element at the given index (supports negative indices).
|
|
160
290
|
*/
|
|
161
291
|
at(index: number): T | undefined;
|
|
292
|
+
/**
|
|
293
|
+
* Returns [index, value] pairs, destructured by for...of.
|
|
294
|
+
*/
|
|
295
|
+
entries(): IterableIterator<[number, T]>;
|
|
162
296
|
/**
|
|
163
297
|
* Returns a string representation of an array.
|
|
164
298
|
*/
|
|
@@ -167,13 +301,28 @@ interface Array<T> extends IterableIterator<T> {
|
|
|
167
301
|
[n: number]: T;
|
|
168
302
|
}
|
|
169
303
|
|
|
304
|
+
interface ArrayConstructor {
|
|
305
|
+
new <T>(length: number): T[];
|
|
306
|
+
isArray(arg: any): arg is any[];
|
|
307
|
+
from<T>(arrayLike: ArrayLike<T>): T[];
|
|
308
|
+
from<T, U>(arrayLike: ArrayLike<T>, mapFn: (value: T, index: number) => U): U[];
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
declare var Array: ArrayConstructor;
|
|
312
|
+
|
|
313
|
+
// --- String ---
|
|
314
|
+
|
|
170
315
|
interface String {
|
|
171
316
|
/** Returns the length of the string. */
|
|
172
317
|
length: number;
|
|
173
318
|
/** Returns the character at the specified index. */
|
|
174
319
|
charAt(pos: number): string;
|
|
320
|
+
/** Returns the Unicode code point at the specified index. */
|
|
321
|
+
charCodeAt(pos: number): number;
|
|
175
322
|
/** Returns the position of the first occurrence of a substring. */
|
|
176
323
|
indexOf(searchString: string): number;
|
|
324
|
+
/** Returns the position of the last occurrence of a substring. */
|
|
325
|
+
lastIndexOf(searchString: string): number;
|
|
177
326
|
/** Determines whether a string contains the specified substring. */
|
|
178
327
|
includes(searchString: string): boolean;
|
|
179
328
|
/** Determines whether a string begins with the specified characters. */
|
|
@@ -181,7 +330,7 @@ interface String {
|
|
|
181
330
|
/** Determines whether a string ends with the specified characters. */
|
|
182
331
|
endsWith(searchString: string): boolean;
|
|
183
332
|
/** Splits a string into substrings using the specified separator. */
|
|
184
|
-
split(separator: string): string[];
|
|
333
|
+
split(separator: string | RegExp): string[];
|
|
185
334
|
/** Removes whitespace from both ends of a string. */
|
|
186
335
|
trim(): string;
|
|
187
336
|
/** Removes whitespace from the beginning of a string. */
|
|
@@ -193,12 +342,13 @@ interface String {
|
|
|
193
342
|
/** Converts all characters to lowercase. */
|
|
194
343
|
toLowerCase(): string;
|
|
195
344
|
/** Replaces the first occurrence of a substring. */
|
|
196
|
-
replace(searchValue: string, replaceValue: string): string;
|
|
345
|
+
replace(searchValue: string | RegExp, replaceValue: string): string;
|
|
346
|
+
replace(searchValue: string | RegExp, replacer: (substring: string, ...args: any[]) => string): string;
|
|
197
347
|
/** Replaces all occurrences of a substring. */
|
|
198
348
|
replaceAll(searchValue: string, replaceValue: string): string;
|
|
199
349
|
/** Returns a section of a string. */
|
|
200
350
|
substring(start: number, end?: number): string;
|
|
201
|
-
/** Returns a section of a string. */
|
|
351
|
+
/** Returns a section of a string (supports negative indices). */
|
|
202
352
|
slice(start: number, end?: number): string;
|
|
203
353
|
/** Returns a string repeated the specified number of times. */
|
|
204
354
|
repeat(count: number): string;
|
|
@@ -214,37 +364,89 @@ interface String {
|
|
|
214
364
|
matchAll(regexp: string | RegExp): string[][];
|
|
215
365
|
/** Searches for a match and returns the index. */
|
|
216
366
|
search(regexp: string | RegExp): number;
|
|
217
|
-
/** Returns the
|
|
367
|
+
/** Returns the character at the given index (supports negative indices). */
|
|
218
368
|
at(index: number): string | undefined;
|
|
369
|
+
/** Compares two strings (by code unit). */
|
|
370
|
+
localeCompare(that: string): number;
|
|
371
|
+
/** Returns the Unicode normalization of the string. */
|
|
372
|
+
normalize(form?: 'NFC' | 'NFD' | 'NFKC' | 'NFKD'): string;
|
|
219
373
|
/** Returns a string representation. */
|
|
220
374
|
toString(): string;
|
|
375
|
+
/** Iterates the string's characters ([...str] spreads runes). */
|
|
376
|
+
[Symbol.iterator](): IterableIterator<string>;
|
|
221
377
|
[index: number]: string;
|
|
222
378
|
}
|
|
223
379
|
|
|
380
|
+
interface StringConstructor {
|
|
381
|
+
(value?: any): string;
|
|
382
|
+
fromCharCode(...charCodes: number[]): string;
|
|
383
|
+
raw(strings: TemplateStringsArray, ...values: any[]): string;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
declare var String: StringConstructor;
|
|
387
|
+
|
|
388
|
+
interface NumberConstructor {
|
|
389
|
+
(value?: any): number;
|
|
390
|
+
isNaN(value: number): boolean;
|
|
391
|
+
isFinite(value: number): boolean;
|
|
392
|
+
isInteger(value: number): boolean;
|
|
393
|
+
readonly MAX_SAFE_INTEGER: number;
|
|
394
|
+
readonly MIN_SAFE_INTEGER: number;
|
|
395
|
+
readonly MAX_VALUE: number;
|
|
396
|
+
readonly POSITIVE_INFINITY: number;
|
|
397
|
+
readonly EPSILON: number;
|
|
398
|
+
readonly NaN: number;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
declare var Number: NumberConstructor;
|
|
402
|
+
|
|
403
|
+
// --- console / globals ---
|
|
404
|
+
|
|
224
405
|
interface Console {
|
|
225
406
|
log(...data: any[]): void;
|
|
226
407
|
error(...data: any[]): void;
|
|
408
|
+
warn(...data: any[]): void;
|
|
227
409
|
time(label?: string): void;
|
|
228
410
|
timeEnd(label?: string): void;
|
|
229
411
|
}
|
|
230
412
|
declare var console: Console;
|
|
231
413
|
|
|
232
414
|
interface Math {
|
|
415
|
+
readonly E: number;
|
|
416
|
+
readonly LN10: number;
|
|
417
|
+
readonly LN2: number;
|
|
418
|
+
readonly LOG10E: number;
|
|
419
|
+
readonly LOG2E: number;
|
|
420
|
+
readonly PI: number;
|
|
421
|
+
readonly SQRT1_2: number;
|
|
422
|
+
readonly SQRT2: number;
|
|
233
423
|
random(): number;
|
|
234
424
|
floor(x: number): number;
|
|
235
425
|
ceil(x: number): number;
|
|
236
426
|
round(x: number): number;
|
|
237
427
|
abs(x: number): number;
|
|
238
|
-
max(
|
|
239
|
-
min(
|
|
428
|
+
max(...values: number[]): number;
|
|
429
|
+
min(...values: number[]): number;
|
|
240
430
|
sqrt(x: number): number;
|
|
241
431
|
pow(base: number, exponent: number): number;
|
|
242
432
|
log(x: number): number;
|
|
243
433
|
log2(x: number): number;
|
|
244
434
|
log10(x: number): number;
|
|
435
|
+
log1p(x: number): number;
|
|
436
|
+
exp(x: number): number;
|
|
437
|
+
expm1(x: number): number;
|
|
245
438
|
sin(x: number): number;
|
|
246
439
|
cos(x: number): number;
|
|
247
440
|
tan(x: number): number;
|
|
441
|
+
asin(x: number): number;
|
|
442
|
+
acos(x: number): number;
|
|
443
|
+
atan(x: number): number;
|
|
444
|
+
atan2(y: number, x: number): number;
|
|
445
|
+
sinh(x: number): number;
|
|
446
|
+
cosh(x: number): number;
|
|
447
|
+
tanh(x: number): number;
|
|
448
|
+
cbrt(x: number): number;
|
|
449
|
+
hypot(...values: number[]): number;
|
|
248
450
|
trunc(x: number): number;
|
|
249
451
|
sign(x: number): number;
|
|
250
452
|
}
|
|
@@ -252,9 +454,31 @@ declare var Math: Math;
|
|
|
252
454
|
|
|
253
455
|
declare function parseInt(s: string, radix?: number): number;
|
|
254
456
|
declare function parseFloat(s: string): number;
|
|
255
|
-
declare function
|
|
256
|
-
declare function
|
|
257
|
-
declare function
|
|
457
|
+
declare function Boolean(value?: any): boolean;
|
|
458
|
+
declare function isNaN(number: number): boolean;
|
|
459
|
+
declare function isFinite(number: number): boolean;
|
|
460
|
+
declare function encodeURIComponent(uriComponent: string): string;
|
|
461
|
+
declare function decodeURIComponent(uriComponent: string): string;
|
|
462
|
+
declare function structuredClone<T>(value: T): T;
|
|
463
|
+
|
|
464
|
+
declare var NaN: number;
|
|
465
|
+
declare var Infinity: number;
|
|
466
|
+
|
|
467
|
+
// globalThis is the global scope itself: `globalThis.x` resolves the global x,
|
|
468
|
+
// `(globalThis as any).x` a dynamic property set.
|
|
469
|
+
|
|
470
|
+
interface ImportMeta {
|
|
471
|
+
readonly url: string;
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
// Timers and microtasks. Handles are opaque; pass them to the matching clear function.
|
|
475
|
+
declare function setTimeout(callback: () => void, ms?: number): number;
|
|
476
|
+
declare function clearTimeout(id?: number): void;
|
|
477
|
+
declare function setInterval(callback: () => void, ms?: number): number;
|
|
478
|
+
declare function clearInterval(id?: number): void;
|
|
479
|
+
declare function queueMicrotask(callback: () => void): void;
|
|
480
|
+
|
|
481
|
+
// --- JSON / Object / process ---
|
|
258
482
|
|
|
259
483
|
interface JSON {
|
|
260
484
|
stringify(value: any, replacer?: any, space?: number | string): string;
|
|
@@ -266,6 +490,21 @@ interface ObjectConstructor {
|
|
|
266
490
|
keys(obj: any): string[];
|
|
267
491
|
values(obj: any): any[];
|
|
268
492
|
entries(obj: any): [string, any][];
|
|
493
|
+
assign(target: any, ...sources: any[]): any;
|
|
494
|
+
fromEntries(entries: Iterable<readonly [string, any]>): any;
|
|
495
|
+
hasOwn(obj: any, key: string): boolean;
|
|
496
|
+
defineProperty<T>(
|
|
497
|
+
obj: T,
|
|
498
|
+
key: string,
|
|
499
|
+
descriptor: { value: any; enumerable?: boolean; writable?: boolean; configurable?: boolean }
|
|
500
|
+
): T;
|
|
501
|
+
getOwnPropertyNames(obj: any): string[];
|
|
502
|
+
freeze<T>(obj: T): T;
|
|
503
|
+
seal<T>(obj: T): T;
|
|
504
|
+
preventExtensions<T>(obj: T): T;
|
|
505
|
+
isFrozen(obj: any): boolean;
|
|
506
|
+
isSealed(obj: any): boolean;
|
|
507
|
+
isExtensible(obj: any): boolean;
|
|
269
508
|
}
|
|
270
509
|
declare var Object: ObjectConstructor;
|
|
271
510
|
|
|
@@ -278,29 +517,84 @@ interface Process {
|
|
|
278
517
|
}
|
|
279
518
|
declare var process: Process;
|
|
280
519
|
|
|
281
|
-
|
|
282
|
-
|
|
520
|
+
// --- Error / Date ---
|
|
521
|
+
|
|
522
|
+
interface Error {
|
|
523
|
+
message: string;
|
|
283
524
|
}
|
|
284
525
|
|
|
285
|
-
interface
|
|
286
|
-
new
|
|
526
|
+
interface ErrorConstructor {
|
|
527
|
+
new (message?: string): Error;
|
|
287
528
|
}
|
|
288
529
|
|
|
289
|
-
declare var
|
|
530
|
+
declare var Error: ErrorConstructor;
|
|
290
531
|
|
|
291
|
-
|
|
532
|
+
interface Date {
|
|
533
|
+
getTime(): number;
|
|
534
|
+
valueOf(): number;
|
|
535
|
+
getFullYear(): number;
|
|
536
|
+
getMonth(): number;
|
|
537
|
+
getDate(): number;
|
|
538
|
+
getDay(): number;
|
|
539
|
+
getHours(): number;
|
|
540
|
+
getMinutes(): number;
|
|
541
|
+
getSeconds(): number;
|
|
542
|
+
getMilliseconds(): number;
|
|
543
|
+
getUTCFullYear(): number;
|
|
544
|
+
getUTCMonth(): number;
|
|
545
|
+
getUTCDate(): number;
|
|
546
|
+
getUTCDay(): number;
|
|
547
|
+
getUTCHours(): number;
|
|
548
|
+
getUTCMinutes(): number;
|
|
549
|
+
getUTCSeconds(): number;
|
|
550
|
+
getUTCMilliseconds(): number;
|
|
551
|
+
toISOString(): string;
|
|
552
|
+
toJSON(): string;
|
|
553
|
+
toString(): string;
|
|
554
|
+
toDateString(): string;
|
|
555
|
+
toTimeString(): string;
|
|
556
|
+
}
|
|
292
557
|
|
|
293
|
-
|
|
558
|
+
interface DateConstructor {
|
|
559
|
+
new (): Date;
|
|
560
|
+
new (ms: number): Date;
|
|
561
|
+
now(): number;
|
|
562
|
+
UTC(
|
|
563
|
+
year: number,
|
|
564
|
+
monthIndex: number,
|
|
565
|
+
date?: number,
|
|
566
|
+
hours?: number,
|
|
567
|
+
minutes?: number,
|
|
568
|
+
seconds?: number,
|
|
569
|
+
ms?: number
|
|
570
|
+
): number;
|
|
571
|
+
}
|
|
294
572
|
|
|
295
|
-
|
|
296
|
-
|
|
573
|
+
declare var Date: DateConstructor;
|
|
574
|
+
|
|
575
|
+
// --- Promise (lowered to goroutines over channels) ---
|
|
576
|
+
|
|
577
|
+
interface Promise<T> {
|
|
578
|
+
then(onfulfilled?: (value: T) => any): void;
|
|
579
|
+
catch(onrejected?: (reason: any) => any): Promise<T>;
|
|
580
|
+
finally(onfinally?: () => void): Promise<T>;
|
|
297
581
|
}
|
|
298
582
|
|
|
299
|
-
interface
|
|
300
|
-
new (
|
|
583
|
+
interface PromiseConstructor {
|
|
584
|
+
new <T>(
|
|
585
|
+
executor: (resolve: (value: T) => void, reject?: (reason?: any) => void) => void
|
|
586
|
+
): Promise<T>;
|
|
587
|
+
resolve<T>(value: T): Promise<T>;
|
|
588
|
+
reject(reason?: any): Promise<never>;
|
|
589
|
+
all<T>(values: Promise<T>[]): Promise<T[]>;
|
|
590
|
+
race<T>(values: Promise<T>[]): Promise<T>;
|
|
591
|
+
any<T>(values: Promise<T>[]): Promise<T>;
|
|
592
|
+
allSettled<T>(values: Promise<T>[]): Promise<{ status: string; value?: T; reason?: any }[]>;
|
|
301
593
|
}
|
|
302
594
|
|
|
303
|
-
declare var
|
|
595
|
+
declare var Promise: PromiseConstructor;
|
|
596
|
+
|
|
597
|
+
// --- Map / Set / WeakMap / WeakSet (ordered Go maps) ---
|
|
304
598
|
|
|
305
599
|
interface Map<K, V> {
|
|
306
600
|
/** The number of key/value pairs in the Map. */
|
|
@@ -315,7 +609,14 @@ interface Map<K, V> {
|
|
|
315
609
|
delete(key: K): boolean;
|
|
316
610
|
/** Removes all entries. */
|
|
317
611
|
clear(): void;
|
|
318
|
-
|
|
612
|
+
/** Performs the callback for each entry in insertion order. */
|
|
613
|
+
forEach(callbackfn: (value: V, key: K, map: Map<K, V>) => void): void;
|
|
614
|
+
/** The keys, in insertion order. */
|
|
615
|
+
keys(): K[];
|
|
616
|
+
/** The values, in insertion order. */
|
|
617
|
+
values(): V[];
|
|
618
|
+
/** Iterates [key, value] pairs in insertion order. */
|
|
619
|
+
[Symbol.iterator](): IterableIterator<[K, V]>;
|
|
319
620
|
}
|
|
320
621
|
|
|
321
622
|
interface MapConstructor {
|
|
@@ -336,12 +637,104 @@ interface Set<T> {
|
|
|
336
637
|
delete(value: T): boolean;
|
|
337
638
|
/** Removes all values. */
|
|
338
639
|
clear(): void;
|
|
339
|
-
|
|
640
|
+
/** Performs the callback for each value in insertion order. */
|
|
641
|
+
forEach(callbackfn: (value: T, value2: T, set: Set<T>) => void): void;
|
|
642
|
+
/** The values, in insertion order. */
|
|
643
|
+
values(): T[];
|
|
644
|
+
union(other: Set<T>): Set<T>;
|
|
645
|
+
intersection(other: Set<T>): Set<T>;
|
|
646
|
+
difference(other: Set<T>): Set<T>;
|
|
647
|
+
symmetricDifference(other: Set<T>): Set<T>;
|
|
648
|
+
isSubsetOf(other: Set<T>): boolean;
|
|
649
|
+
isSupersetOf(other: Set<T>): boolean;
|
|
650
|
+
isDisjointFrom(other: Set<T>): boolean;
|
|
651
|
+
/** Iterates the values in insertion order. */
|
|
652
|
+
[Symbol.iterator](): IterableIterator<T>;
|
|
340
653
|
}
|
|
341
654
|
|
|
342
655
|
interface SetConstructor {
|
|
343
656
|
new <T>(): Set<T>;
|
|
344
|
-
new <T>(values
|
|
657
|
+
new <T>(values?: T[] | Set<T>): Set<T>;
|
|
345
658
|
}
|
|
346
659
|
|
|
347
660
|
declare var Set: SetConstructor;
|
|
661
|
+
|
|
662
|
+
// WeakMap/WeakSet lower to Map/Set with the same API; weakness is not observable.
|
|
663
|
+
interface WeakMap<K extends object, V> {
|
|
664
|
+
set(key: K, value: V): this;
|
|
665
|
+
get(key: K): V | undefined;
|
|
666
|
+
has(key: K): boolean;
|
|
667
|
+
delete(key: K): boolean;
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
interface WeakMapConstructor {
|
|
671
|
+
new <K extends object, V>(): WeakMap<K, V>;
|
|
672
|
+
new <K extends object, V>(entries?: [K, V][]): WeakMap<K, V>;
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
declare var WeakMap: WeakMapConstructor;
|
|
676
|
+
|
|
677
|
+
interface WeakSet<T extends object> {
|
|
678
|
+
add(value: T): this;
|
|
679
|
+
has(value: T): boolean;
|
|
680
|
+
delete(value: T): boolean;
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
interface WeakSetConstructor {
|
|
684
|
+
new <T extends object>(): WeakSet<T>;
|
|
685
|
+
new <T extends object>(values?: T[]): WeakSet<T>;
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
declare var WeakSet: WeakSetConstructor;
|
|
689
|
+
|
|
690
|
+
// --- Symbol ---
|
|
691
|
+
|
|
692
|
+
interface SymbolConstructor {
|
|
693
|
+
(description?: string | number): symbol;
|
|
694
|
+
readonly iterator: unique symbol;
|
|
695
|
+
readonly asyncIterator: unique symbol;
|
|
696
|
+
readonly dispose: unique symbol;
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
declare var Symbol: SymbolConstructor;
|
|
700
|
+
|
|
701
|
+
// --- Decorators (class and class-method decorators are lowered) ---
|
|
702
|
+
|
|
703
|
+
interface ClassDecoratorContext<Class extends abstract new (...args: any) => any = abstract new (...args: any) => any> {
|
|
704
|
+
readonly kind: 'class';
|
|
705
|
+
readonly name: string | undefined;
|
|
706
|
+
addInitializer(initializer: (this: Class) => void): void;
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
interface ClassMethodDecoratorContext<
|
|
710
|
+
This = unknown,
|
|
711
|
+
Value extends (this: This, ...args: any) => any = (this: This, ...args: any) => any,
|
|
712
|
+
> {
|
|
713
|
+
readonly kind: 'method';
|
|
714
|
+
readonly name: string | symbol;
|
|
715
|
+
readonly static: boolean;
|
|
716
|
+
readonly private: boolean;
|
|
717
|
+
readonly access: {
|
|
718
|
+
has(object: This): boolean;
|
|
719
|
+
get(object: This): Value;
|
|
720
|
+
};
|
|
721
|
+
addInitializer(initializer: (this: This) => void): void;
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
// --- Test helper ---
|
|
725
|
+
|
|
726
|
+
declare function assert(condition: boolean, message?: string): void;
|
|
727
|
+
|
|
728
|
+
// --- JSX (.tsx renders to HTML strings) ---
|
|
729
|
+
|
|
730
|
+
declare namespace JSX {
|
|
731
|
+
// A JSX expression is an HTML string; multiple children form a list that
|
|
732
|
+
// concatenates to one string.
|
|
733
|
+
type Element = string | readonly Element[];
|
|
734
|
+
interface IntrinsicElements {
|
|
735
|
+
[name: string]: any;
|
|
736
|
+
}
|
|
737
|
+
interface ElementChildrenAttribute {
|
|
738
|
+
children: {};
|
|
739
|
+
}
|
|
740
|
+
}
|