@tsonic/js-globals 0.1.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.
Files changed (4) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +124 -0
  3. package/index.d.ts +626 -0
  4. package/package.json +24 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 tsoniclang
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,124 @@
1
+ # @tsonic/js-globals
2
+
3
+ Global type definitions for Tsonic in **JS mode** (JavaScript semantics).
4
+
5
+ ## Purpose
6
+
7
+ This package provides JavaScript built-in types and methods for TypeScript when `noLib: true` is set, enabling JavaScript-style programming in Tsonic code while compiling to C# with `Tsonic.JSRuntime`.
8
+
9
+ **Key principle:** In JS mode, JavaScript array/string methods ARE available and compile to `Tsonic.JSRuntime` extension methods.
10
+
11
+ ## Usage
12
+
13
+ Install this package in your Tsonic project:
14
+
15
+ ```bash
16
+ npm install @tsonic/js-globals
17
+ ```
18
+
19
+ Add to your `tsconfig.json`:
20
+
21
+ ```json
22
+ {
23
+ "compilerOptions": {
24
+ "noLib": true,
25
+ "types": ["@tsonic/js-globals"]
26
+ }
27
+ }
28
+ ```
29
+
30
+ Set your `tsonic.json` mode:
31
+
32
+ ```json
33
+ {
34
+ "mode": "js"
35
+ }
36
+ ```
37
+
38
+ ## What This Provides
39
+
40
+ ### Full JavaScript API
41
+
42
+ - `Array<T>` - **WITH** all JS methods: `.length`, `.map()`, `.filter()`, `.reduce()`, etc.
43
+ - `String` - **WITH** all JS methods: `.slice()`, `.includes()`, `.split()`, etc.
44
+ - `Number`, `Boolean`, `Object`, `Function` - full JavaScript definitions
45
+ - `Math` - all math functions
46
+ - `JSON` - `parse()` and `stringify()`
47
+ - `console` - `log()`, `error()`, `warn()`, etc.
48
+ - `Promise<T>` - for async/await support
49
+ - `RegExp` - regular expressions
50
+ - Iterator types - for `for-of` loops
51
+
52
+ ### What's NOT Included
53
+
54
+ - **No DOM types** - no `Document`, `HTMLElement`, `window`, etc.
55
+ - **No Node.js types** - no `Buffer`, `process`, `require`, etc.
56
+ - **No Browser APIs** - no `fetch`, `localStorage`, `XMLHttpRequest`, etc.
57
+
58
+ This is intentional - Tsonic compiles to native executables, not browser/Node.js environments.
59
+
60
+ ## Example
61
+
62
+ ```typescript
63
+ // Array methods work just like JavaScript
64
+ const numbers = [1, 2, 3, 4, 5];
65
+
66
+ // ✅ All JavaScript array methods available
67
+ console.log(numbers.length); // 5
68
+ const doubled = numbers.map(x => x * 2); // [2, 4, 6, 8, 10]
69
+ const evens = numbers.filter(x => x % 2 === 0); // [2, 4]
70
+ const sum = numbers.reduce((a, b) => a + b, 0); // 15
71
+
72
+ // ✅ String methods work
73
+ const message = "Hello, Tsonic!";
74
+ console.log(message.length); // 14
75
+ console.log(message.slice(0, 5)); // "Hello"
76
+ console.log(message.includes("Tsonic")); // true
77
+
78
+ // ✅ Math functions
79
+ const result = Math.round(3.7); // 4
80
+ const random = Math.random(); // 0.0 to 1.0
81
+
82
+ // ✅ JSON operations
83
+ const obj = { name: "Alice", age: 30 };
84
+ const json = JSON.stringify(obj); // '{"name":"Alice","age":30}'
85
+ const parsed = JSON.parse(json); // { name: "Alice", age: 30 }
86
+ ```
87
+
88
+ ## How It Works
89
+
90
+ When you use JS mode:
91
+
92
+ 1. **TypeScript sees** JavaScript APIs (via this package)
93
+ 2. **Tsonic compiler emits** calls to `Tsonic.JSRuntime` extension methods
94
+ 3. **C# code uses** `Tsonic.JSRuntime` package for JS semantics
95
+ 4. **Result:** JavaScript behavior in a native executable
96
+
97
+ Example compilation:
98
+
99
+ ```typescript
100
+ // TypeScript (JS mode)
101
+ const nums = [1, 2, 3];
102
+ const doubled = nums.map(x => x * 2);
103
+ ```
104
+
105
+ ```csharp
106
+ // Generated C# (uses Tsonic.JSRuntime)
107
+ using Tsonic.JSRuntime;
108
+
109
+ var nums = new List<int> { 1, 2, 3 };
110
+ var doubled = nums.JSMap(x => x * 2);
111
+ ```
112
+
113
+ ## Mode Switching
114
+
115
+ To switch to .NET semantics (without `.length`, `.map()`, etc.), use `@tsonic/dotnet-globals` instead:
116
+
117
+ 1. Uninstall this package: `npm uninstall @tsonic/js-globals`
118
+ 2. Install dotnet globals: `npm install @tsonic/dotnet-globals`
119
+ 3. Update `tsconfig.json`: `"types": ["@tsonic/dotnet-globals"]`
120
+ 4. Update `tsonic.json`: `"mode": "dotnet"` (or omit, dotnet is default)
121
+
122
+ ## License
123
+
124
+ MIT
package/index.d.ts ADDED
@@ -0,0 +1,626 @@
1
+ /**
2
+ * @tsonic/js-globals
3
+ *
4
+ * Global type definitions for Tsonic in JS mode.
5
+ *
6
+ * These provide JavaScript built-in types and methods for TypeScript
7
+ * when noLib: true is set, enabling JavaScript semantics in Tsonic code.
8
+ *
9
+ * Key principle: Array<T> HAS JS members like .length and .map
10
+ * This enables JS-style programming while compiling to C# with Tsonic.JSRuntime
11
+ */
12
+
13
+ declare global {
14
+ /**
15
+ * Primitive types (required by TypeScript compiler)
16
+ */
17
+ type string = string;
18
+ type number = number;
19
+ type boolean = boolean;
20
+ type symbol = symbol;
21
+ type bigint = bigint;
22
+ type undefined = undefined;
23
+ type null = null;
24
+ type any = any;
25
+ type unknown = unknown;
26
+ type never = never;
27
+ type void = void;
28
+
29
+ /**
30
+ * Array type with full JavaScript API
31
+ * In JS mode, these compile to Tsonic.JSRuntime extension methods
32
+ */
33
+ interface Array<T> {
34
+ /**
35
+ * Gets or sets the length of the array.
36
+ */
37
+ length: number;
38
+
39
+ /**
40
+ * Returns the item located at the specified index.
41
+ */
42
+ [n: number]: T;
43
+
44
+ /**
45
+ * Appends new elements to the end of an array, and returns the new length.
46
+ */
47
+ push(...items: T[]): number;
48
+
49
+ /**
50
+ * Removes the last element from an array and returns it.
51
+ */
52
+ pop(): T | undefined;
53
+
54
+ /**
55
+ * Removes the first element from an array and returns it.
56
+ */
57
+ shift(): T | undefined;
58
+
59
+ /**
60
+ * Inserts new elements at the start of an array, and returns the new length.
61
+ */
62
+ unshift(...items: T[]): number;
63
+
64
+ /**
65
+ * Returns a copy of a section of an array.
66
+ */
67
+ slice(start?: number, end?: number): T[];
68
+
69
+ /**
70
+ * Removes elements from an array and, if necessary, inserts new elements, returning deleted elements.
71
+ */
72
+ splice(start: number, deleteCount?: number, ...items: T[]): T[];
73
+
74
+ /**
75
+ * Returns the index of the first occurrence of a value in an array, or -1 if it is not present.
76
+ */
77
+ indexOf(searchElement: T, fromIndex?: number): number;
78
+
79
+ /**
80
+ * Returns the index of the last occurrence of a specified value in an array, or -1 if it is not present.
81
+ */
82
+ lastIndexOf(searchElement: T, fromIndex?: number): number;
83
+
84
+ /**
85
+ * Determines whether all the members of an array satisfy the specified test.
86
+ */
87
+ every(predicate: (value: T, index: number, array: T[]) => unknown): boolean;
88
+
89
+ /**
90
+ * Determines whether the specified callback function returns true for any element of an array.
91
+ */
92
+ some(predicate: (value: T, index: number, array: T[]) => unknown): boolean;
93
+
94
+ /**
95
+ * Performs the specified action for each element in an array.
96
+ */
97
+ forEach(callbackfn: (value: T, index: number, array: T[]) => void): void;
98
+
99
+ /**
100
+ * Calls a defined callback function on each element of an array, and returns an array of the results.
101
+ */
102
+ map<U>(callbackfn: (value: T, index: number, array: T[]) => U): U[];
103
+
104
+ /**
105
+ * Returns the elements of an array that meet the condition specified in a callback function.
106
+ */
107
+ filter(predicate: (value: T, index: number, array: T[]) => unknown): T[];
108
+
109
+ /**
110
+ * Calls the specified callback function for all the elements in an array. The return value is the accumulated result.
111
+ */
112
+ reduce<U>(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: T[]) => U, initialValue: U): U;
113
+
114
+ /**
115
+ * Returns the value of the first element in the array where predicate is true, and undefined otherwise.
116
+ */
117
+ find(predicate: (value: T, index: number, array: T[]) => unknown): T | undefined;
118
+
119
+ /**
120
+ * Returns the index of the first element in the array where predicate is true, and -1 otherwise.
121
+ */
122
+ findIndex(predicate: (value: T, index: number, array: T[]) => unknown): number;
123
+
124
+ /**
125
+ * Determines whether an array includes a certain element.
126
+ */
127
+ includes(searchElement: T, fromIndex?: number): boolean;
128
+
129
+ /**
130
+ * Sorts an array in place.
131
+ */
132
+ sort(compareFn?: (a: T, b: T) => number): this;
133
+
134
+ /**
135
+ * Reverses the elements in an array in place.
136
+ */
137
+ reverse(): T[];
138
+
139
+ /**
140
+ * Combines two or more arrays.
141
+ */
142
+ concat(...items: (T | T[])[]): T[];
143
+
144
+ /**
145
+ * Adds all the elements of an array into a string, separated by the specified separator string.
146
+ */
147
+ join(separator?: string): string;
148
+
149
+ /**
150
+ * Returns the value of the element at the specified index, or undefined if the index is out of bounds.
151
+ */
152
+ at(index: number): T | undefined;
153
+
154
+ /**
155
+ * Returns a new array with all sub-array elements concatenated into it recursively up to the specified depth.
156
+ */
157
+ flat<D extends number = 1>(depth?: D): any[];
158
+
159
+ /**
160
+ * Calls a defined callback function on each element of an array, and then flattens the result by one level.
161
+ */
162
+ flatMap<U>(callback: (value: T, index: number, array: T[]) => U | U[]): U[];
163
+ }
164
+
165
+ interface ReadonlyArray<T> {
166
+ readonly length: number;
167
+ readonly [n: number]: T;
168
+ slice(start?: number, end?: number): T[];
169
+ indexOf(searchElement: T, fromIndex?: number): number;
170
+ lastIndexOf(searchElement: T, fromIndex?: number): number;
171
+ every(predicate: (value: T, index: number, array: readonly T[]) => unknown): boolean;
172
+ some(predicate: (value: T, index: number, array: readonly T[]) => unknown): boolean;
173
+ forEach(callbackfn: (value: T, index: number, array: readonly T[]) => void): void;
174
+ map<U>(callbackfn: (value: T, index: number, array: readonly T[]) => U): U[];
175
+ filter(predicate: (value: T, index: number, array: readonly T[]) => unknown): T[];
176
+ reduce<U>(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: readonly T[]) => U, initialValue: U): U;
177
+ find(predicate: (value: T, index: number, array: readonly T[]) => unknown): T | undefined;
178
+ findIndex(predicate: (value: T, index: number, array: readonly T[]) => unknown): number;
179
+ includes(searchElement: T, fromIndex?: number): boolean;
180
+ concat(...items: (T | readonly T[])[]): T[];
181
+ join(separator?: string): string;
182
+ at(index: number): T | undefined;
183
+ }
184
+
185
+ interface ArrayConstructor {
186
+ new <T>(...items: T[]): T[];
187
+ isArray(arg: any): arg is any[];
188
+ from<T>(arrayLike: ArrayLike<T>): T[];
189
+ from<T, U>(arrayLike: ArrayLike<T>, mapfn: (v: T, k: number) => U): U[];
190
+ of<T>(...items: T[]): T[];
191
+ }
192
+
193
+ const Array: ArrayConstructor;
194
+
195
+ /**
196
+ * String type with full JavaScript API
197
+ */
198
+ interface String {
199
+ /**
200
+ * Returns the length of a String object.
201
+ */
202
+ readonly length: number;
203
+
204
+ /**
205
+ * Returns the character at the specified index.
206
+ */
207
+ charAt(pos: number): string;
208
+
209
+ /**
210
+ * Returns the Unicode value of the character at the specified location.
211
+ */
212
+ charCodeAt(index: number): number;
213
+
214
+ /**
215
+ * Returns a string that contains the concatenation of two or more strings.
216
+ */
217
+ concat(...strings: string[]): string;
218
+
219
+ /**
220
+ * Returns the position of the first occurrence of a substring.
221
+ */
222
+ indexOf(searchString: string, position?: number): number;
223
+
224
+ /**
225
+ * Returns the last occurrence of a substring in the string.
226
+ */
227
+ lastIndexOf(searchString: string, position?: number): number;
228
+
229
+ /**
230
+ * Determines whether a string contains another string.
231
+ */
232
+ includes(searchString: string, position?: number): boolean;
233
+
234
+ /**
235
+ * Determines whether a string begins with the characters of a specified string.
236
+ */
237
+ startsWith(searchString: string, position?: number): boolean;
238
+
239
+ /**
240
+ * Determines whether a string ends with the characters of a specified string.
241
+ */
242
+ endsWith(searchString: string, endPosition?: number): boolean;
243
+
244
+ /**
245
+ * Returns a copy of this string starting at the specified index.
246
+ */
247
+ slice(start?: number, end?: number): string;
248
+
249
+ /**
250
+ * Returns a section of a string.
251
+ */
252
+ substring(start: number, end?: number): string;
253
+
254
+ /**
255
+ * Gets a substring beginning at the specified location and having the specified length.
256
+ */
257
+ substr(from: number, length?: number): string;
258
+
259
+ /**
260
+ * Converts all the alphabetic characters in a string to lowercase.
261
+ */
262
+ toLowerCase(): string;
263
+
264
+ /**
265
+ * Converts all the alphabetic characters in a string to uppercase.
266
+ */
267
+ toUpperCase(): string;
268
+
269
+ /**
270
+ * Removes the leading and trailing white space and line terminator characters from a string.
271
+ */
272
+ trim(): string;
273
+
274
+ /**
275
+ * Removes the trailing white space and line terminator characters from a string.
276
+ */
277
+ trimEnd(): string;
278
+
279
+ /**
280
+ * Removes the leading white space and line terminator characters from a string.
281
+ */
282
+ trimStart(): string;
283
+
284
+ /**
285
+ * Pads the current string with a given string to a given length from the start.
286
+ */
287
+ padStart(targetLength: number, padString?: string): string;
288
+
289
+ /**
290
+ * Pads the current string with a given string to a given length from the end.
291
+ */
292
+ padEnd(targetLength: number, padString?: string): string;
293
+
294
+ /**
295
+ * Returns a string that is repeated the specified number of times.
296
+ */
297
+ repeat(count: number): string;
298
+
299
+ /**
300
+ * Replaces text in a string, using a regular expression or search string.
301
+ */
302
+ replace(searchValue: string | RegExp, replaceValue: string): string;
303
+
304
+ /**
305
+ * Split a string into substrings using the specified separator.
306
+ */
307
+ split(separator: string | RegExp, limit?: number): string[];
308
+
309
+ /**
310
+ * Matches a string with a regular expression.
311
+ */
312
+ match(regexp: RegExp): RegExpMatchArray | null;
313
+
314
+ /**
315
+ * Searches for a match in a string, and returns the index.
316
+ */
317
+ search(regexp: RegExp): number;
318
+ }
319
+
320
+ interface StringConstructor {
321
+ new (value?: any): String;
322
+ (value?: any): string;
323
+ fromCharCode(...codes: number[]): string;
324
+ }
325
+
326
+ const String: StringConstructor;
327
+
328
+ /**
329
+ * Number type
330
+ */
331
+ interface Number {
332
+ toString(radix?: number): string;
333
+ toFixed(fractionDigits?: number): string;
334
+ toExponential(fractionDigits?: number): string;
335
+ toPrecision(precision?: number): string;
336
+ }
337
+
338
+ interface NumberConstructor {
339
+ new (value?: any): Number;
340
+ (value?: any): number;
341
+ readonly MAX_VALUE: number;
342
+ readonly MIN_VALUE: number;
343
+ readonly NaN: number;
344
+ readonly NEGATIVE_INFINITY: number;
345
+ readonly POSITIVE_INFINITY: number;
346
+ isFinite(value: unknown): value is number;
347
+ isInteger(value: unknown): value is number;
348
+ isNaN(value: unknown): value is number;
349
+ isSafeInteger(value: unknown): value is number;
350
+ parseFloat(string: string): number;
351
+ parseInt(string: string, radix?: number): number;
352
+ }
353
+
354
+ const Number: NumberConstructor;
355
+
356
+ /**
357
+ * Boolean type
358
+ */
359
+ interface Boolean {}
360
+
361
+ interface BooleanConstructor {
362
+ new (value?: any): Boolean;
363
+ (value?: any): boolean;
364
+ }
365
+
366
+ const Boolean: BooleanConstructor;
367
+
368
+ /**
369
+ * Object type
370
+ */
371
+ interface Object {
372
+ constructor: Function;
373
+ toString(): string;
374
+ hasOwnProperty(v: PropertyKey): boolean;
375
+ }
376
+
377
+ interface ObjectConstructor {
378
+ new (value?: any): Object;
379
+ (): any;
380
+ (value: any): any;
381
+ keys(o: object): string[];
382
+ values<T>(o: { [s: string]: T }): T[];
383
+ entries<T>(o: { [s: string]: T }): [string, T][];
384
+ assign<T, U>(target: T, source: U): T & U;
385
+ }
386
+
387
+ const Object: ObjectConstructor;
388
+
389
+ /**
390
+ * Function type
391
+ */
392
+ interface Function {
393
+ prototype: any;
394
+ readonly length: number;
395
+ call(thisArg: any, ...argArray: any[]): any;
396
+ apply(thisArg: any, argArray?: any): any;
397
+ bind(thisArg: any, ...argArray: any[]): any;
398
+ }
399
+
400
+ interface CallableFunction extends Function {}
401
+ interface NewableFunction extends Function {}
402
+
403
+ interface FunctionConstructor {
404
+ new (...args: string[]): Function;
405
+ (...args: string[]): Function;
406
+ }
407
+
408
+ const Function: FunctionConstructor;
409
+
410
+ /**
411
+ * RegExp type
412
+ */
413
+ interface RegExp {
414
+ exec(string: string): RegExpExecArray | null;
415
+ test(string: string): boolean;
416
+ readonly source: string;
417
+ readonly global: boolean;
418
+ readonly ignoreCase: boolean;
419
+ readonly multiline: boolean;
420
+ lastIndex: number;
421
+ }
422
+
423
+ interface RegExpConstructor {
424
+ new (pattern: string | RegExp, flags?: string): RegExp;
425
+ (pattern: string | RegExp, flags?: string): RegExp;
426
+ }
427
+
428
+ const RegExp: RegExpConstructor;
429
+
430
+ interface RegExpExecArray extends Array<string> {
431
+ index: number;
432
+ input: string;
433
+ }
434
+
435
+ interface RegExpMatchArray extends Array<string> {
436
+ index?: number;
437
+ input?: string;
438
+ }
439
+
440
+ /**
441
+ * Symbol type
442
+ */
443
+ interface SymbolConstructor {
444
+ readonly iterator: symbol;
445
+ readonly asyncIterator: symbol;
446
+ readonly hasInstance: symbol;
447
+ readonly isConcatSpreadable: symbol;
448
+ readonly species: symbol;
449
+ readonly toPrimitive: symbol;
450
+ readonly toStringTag: symbol;
451
+ }
452
+
453
+ const Symbol: SymbolConstructor;
454
+
455
+ type PropertyKey = string | number | symbol;
456
+
457
+ /**
458
+ * Math object
459
+ */
460
+ interface Math {
461
+ readonly E: number;
462
+ readonly LN10: number;
463
+ readonly LN2: number;
464
+ readonly LOG2E: number;
465
+ readonly LOG10E: number;
466
+ readonly PI: number;
467
+ readonly SQRT1_2: number;
468
+ readonly SQRT2: number;
469
+ abs(x: number): number;
470
+ acos(x: number): number;
471
+ asin(x: number): number;
472
+ atan(x: number): number;
473
+ atan2(y: number, x: number): number;
474
+ ceil(x: number): number;
475
+ cos(x: number): number;
476
+ exp(x: number): number;
477
+ floor(x: number): number;
478
+ log(x: number): number;
479
+ max(...values: number[]): number;
480
+ min(...values: number[]): number;
481
+ pow(x: number, y: number): number;
482
+ random(): number;
483
+ round(x: number): number;
484
+ sin(x: number): number;
485
+ sqrt(x: number): number;
486
+ tan(x: number): number;
487
+ }
488
+
489
+ const Math: Math;
490
+
491
+ /**
492
+ * JSON object
493
+ */
494
+ interface JSON {
495
+ parse(text: string, reviver?: (this: any, key: string, value: any) => any): any;
496
+ stringify(value: any, replacer?: (this: any, key: string, value: any) => any, space?: string | number): string;
497
+ stringify(value: any, replacer?: (number | string)[] | null, space?: string | number): string;
498
+ }
499
+
500
+ const JSON: JSON;
501
+
502
+ /**
503
+ * Console object
504
+ */
505
+ interface Console {
506
+ log(...data: any[]): void;
507
+ error(...data: any[]): void;
508
+ warn(...data: any[]): void;
509
+ info(...data: any[]): void;
510
+ debug(...data: any[]): void;
511
+ }
512
+
513
+ const console: Console;
514
+
515
+ /**
516
+ * Error types
517
+ */
518
+ interface Error {
519
+ name: string;
520
+ message: string;
521
+ stack?: string;
522
+ }
523
+
524
+ interface ErrorConstructor {
525
+ new (message?: string): Error;
526
+ (message?: string): Error;
527
+ }
528
+
529
+ const Error: ErrorConstructor;
530
+
531
+ /**
532
+ * Utility types (built into TypeScript)
533
+ */
534
+ type Partial<T> = { [P in keyof T]?: T[P] };
535
+ type Required<T> = { [P in keyof T]-?: T[P] };
536
+ type Readonly<T> = { readonly [P in keyof T]: T[P] };
537
+ type Pick<T, K extends keyof T> = { [P in K]: T[P] };
538
+ type Record<K extends keyof any, T> = { [P in K]: T };
539
+ type Exclude<T, U> = T extends U ? never : T;
540
+ type Extract<T, U> = T extends U ? T : never;
541
+ type Omit<T, K extends keyof any> = Pick<T, Exclude<keyof T, K>>;
542
+ type NonNullable<T> = T extends null | undefined ? never : T;
543
+ type Parameters<T extends (...args: any) => any> = T extends (...args: infer P) => any ? P : never;
544
+ type ConstructorParameters<T extends new (...args: any) => any> = T extends new (...args: infer P) => any ? P : never;
545
+ type ReturnType<T extends (...args: any) => any> = T extends (...args: any) => infer R ? R : any;
546
+ type InstanceType<T extends new (...args: any) => any> = T extends new (...args: any) => infer R ? R : any;
547
+
548
+ /**
549
+ * Promise type
550
+ */
551
+ interface Promise<T> {
552
+ then<TResult1 = T, TResult2 = never>(
553
+ onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | undefined | null,
554
+ onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null
555
+ ): Promise<TResult1 | TResult2>;
556
+ catch<TResult = never>(
557
+ onrejected?: ((reason: any) => TResult | PromiseLike<TResult>) | undefined | null
558
+ ): Promise<T | TResult>;
559
+ finally(onfinally?: (() => void) | undefined | null): Promise<T>;
560
+ }
561
+
562
+ interface PromiseLike<T> {
563
+ then<TResult1 = T, TResult2 = never>(
564
+ onfulfilled?: ((value: T) => TResult1 | PromiseLike<TResult1>) | undefined | null,
565
+ onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null
566
+ ): PromiseLike<TResult1 | TResult2>;
567
+ }
568
+
569
+ interface PromiseConstructor {
570
+ new <T>(executor: (resolve: (value: T | PromiseLike<T>) => void, reject: (reason?: any) => void) => void): Promise<T>;
571
+ resolve(): Promise<void>;
572
+ resolve<T>(value: T | PromiseLike<T>): Promise<T>;
573
+ reject<T = never>(reason?: any): Promise<T>;
574
+ all<T>(values: readonly (T | PromiseLike<T>)[]): Promise<T[]>;
575
+ race<T>(values: readonly (T | PromiseLike<T>)[]): Promise<T>;
576
+ }
577
+
578
+ const Promise: PromiseConstructor;
579
+
580
+ /**
581
+ * Iterator types
582
+ */
583
+ interface Iterator<T> {
584
+ next(): IteratorResult<T>;
585
+ return?(value?: any): IteratorResult<T>;
586
+ throw?(e?: any): IteratorResult<T>;
587
+ }
588
+
589
+ interface IteratorResult<T> {
590
+ done: boolean;
591
+ value: T;
592
+ }
593
+
594
+ interface Iterable<T> {
595
+ [Symbol.iterator](): Iterator<T>;
596
+ }
597
+
598
+ interface IterableIterator<T> extends Iterator<T> {
599
+ [Symbol.iterator](): IterableIterator<T>;
600
+ }
601
+
602
+ /**
603
+ * Template literal type utilities
604
+ */
605
+ type Uppercase<S extends string> = intrinsic;
606
+ type Lowercase<S extends string> = intrinsic;
607
+ type Capitalize<S extends string> = intrinsic;
608
+ type Uncapitalize<S extends string> = intrinsic;
609
+
610
+ /**
611
+ * Additional types
612
+ */
613
+ interface IArguments {
614
+ [index: number]: any;
615
+ length: number;
616
+ callee: Function;
617
+ }
618
+
619
+ interface ArrayLike<T> {
620
+ readonly length: number;
621
+ readonly [n: number]: T;
622
+ }
623
+ }
624
+
625
+ // This export is required to make this file a module
626
+ export {};
package/package.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "@tsonic/js-globals",
3
+ "version": "0.1.0",
4
+ "description": "Global type definitions for Tsonic JS mode (noLib: true, JavaScript semantics)",
5
+ "main": "index.d.ts",
6
+ "types": "index.d.ts",
7
+ "files": [
8
+ "index.d.ts",
9
+ "README.md"
10
+ ],
11
+ "keywords": [
12
+ "tsonic",
13
+ "typescript",
14
+ "javascript",
15
+ "types",
16
+ "globals"
17
+ ],
18
+ "author": "Tsonic Team",
19
+ "license": "MIT",
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "https://github.com/tsoniclang/js-globals.git"
23
+ }
24
+ }