@tsonic/js-globals 0.1.1 → 0.2.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.
- package/index.d.ts +22 -31
- package/package.json +10 -1
package/index.d.ts
CHANGED
|
@@ -8,23 +8,14 @@
|
|
|
8
8
|
*
|
|
9
9
|
* Key principle: Array<T> HAS JS members like .length and .map
|
|
10
10
|
* This enables JS-style programming while compiling to C# with Tsonic.JSRuntime
|
|
11
|
+
*
|
|
12
|
+
* Index-space values (length, indexOf, etc.) use branded `int` type from
|
|
13
|
+
* @tsonic/types to enable numeric proof validation for array indexing.
|
|
11
14
|
*/
|
|
12
15
|
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Primitive types (required by TypeScript compiler)
|
|
16
|
-
* Note: null, void are intrinsic and don't need type aliases
|
|
17
|
-
*/
|
|
18
|
-
type string = string;
|
|
19
|
-
type number = number;
|
|
20
|
-
type boolean = boolean;
|
|
21
|
-
type symbol = symbol;
|
|
22
|
-
type bigint = bigint;
|
|
23
|
-
type undefined = undefined;
|
|
24
|
-
type any = any;
|
|
25
|
-
type unknown = unknown;
|
|
26
|
-
type never = never;
|
|
16
|
+
import { int } from "@tsonic/types";
|
|
27
17
|
|
|
18
|
+
declare global {
|
|
28
19
|
/**
|
|
29
20
|
* Array type with full JavaScript API
|
|
30
21
|
* In JS mode, these compile to Tsonic.JSRuntime extension methods
|
|
@@ -33,7 +24,7 @@ declare global {
|
|
|
33
24
|
/**
|
|
34
25
|
* Gets or sets the length of the array.
|
|
35
26
|
*/
|
|
36
|
-
length:
|
|
27
|
+
length: int;
|
|
37
28
|
|
|
38
29
|
/**
|
|
39
30
|
* Returns the item located at the specified index.
|
|
@@ -43,7 +34,7 @@ declare global {
|
|
|
43
34
|
/**
|
|
44
35
|
* Appends new elements to the end of an array, and returns the new length.
|
|
45
36
|
*/
|
|
46
|
-
push(...items: T[]):
|
|
37
|
+
push(...items: T[]): int;
|
|
47
38
|
|
|
48
39
|
/**
|
|
49
40
|
* Removes the last element from an array and returns it.
|
|
@@ -58,7 +49,7 @@ declare global {
|
|
|
58
49
|
/**
|
|
59
50
|
* Inserts new elements at the start of an array, and returns the new length.
|
|
60
51
|
*/
|
|
61
|
-
unshift(...items: T[]):
|
|
52
|
+
unshift(...items: T[]): int;
|
|
62
53
|
|
|
63
54
|
/**
|
|
64
55
|
* Returns a copy of a section of an array.
|
|
@@ -73,12 +64,12 @@ declare global {
|
|
|
73
64
|
/**
|
|
74
65
|
* Returns the index of the first occurrence of a value in an array, or -1 if it is not present.
|
|
75
66
|
*/
|
|
76
|
-
indexOf(searchElement: T, fromIndex?: number):
|
|
67
|
+
indexOf(searchElement: T, fromIndex?: number): int;
|
|
77
68
|
|
|
78
69
|
/**
|
|
79
70
|
* Returns the index of the last occurrence of a specified value in an array, or -1 if it is not present.
|
|
80
71
|
*/
|
|
81
|
-
lastIndexOf(searchElement: T, fromIndex?: number):
|
|
72
|
+
lastIndexOf(searchElement: T, fromIndex?: number): int;
|
|
82
73
|
|
|
83
74
|
/**
|
|
84
75
|
* Determines whether all the members of an array satisfy the specified test.
|
|
@@ -118,7 +109,7 @@ declare global {
|
|
|
118
109
|
/**
|
|
119
110
|
* Returns the index of the first element in the array where predicate is true, and -1 otherwise.
|
|
120
111
|
*/
|
|
121
|
-
findIndex(predicate: (value: T, index: number, array: T[]) => unknown):
|
|
112
|
+
findIndex(predicate: (value: T, index: number, array: T[]) => unknown): int;
|
|
122
113
|
|
|
123
114
|
/**
|
|
124
115
|
* Determines whether an array includes a certain element.
|
|
@@ -162,11 +153,11 @@ declare global {
|
|
|
162
153
|
}
|
|
163
154
|
|
|
164
155
|
interface ReadonlyArray<T> {
|
|
165
|
-
readonly length:
|
|
156
|
+
readonly length: int;
|
|
166
157
|
readonly [n: number]: T;
|
|
167
158
|
slice(start?: number, end?: number): T[];
|
|
168
|
-
indexOf(searchElement: T, fromIndex?: number):
|
|
169
|
-
lastIndexOf(searchElement: T, fromIndex?: number):
|
|
159
|
+
indexOf(searchElement: T, fromIndex?: number): int;
|
|
160
|
+
lastIndexOf(searchElement: T, fromIndex?: number): int;
|
|
170
161
|
every(predicate: (value: T, index: number, array: readonly T[]) => unknown): boolean;
|
|
171
162
|
some(predicate: (value: T, index: number, array: readonly T[]) => unknown): boolean;
|
|
172
163
|
forEach(callbackfn: (value: T, index: number, array: readonly T[]) => void): void;
|
|
@@ -174,7 +165,7 @@ declare global {
|
|
|
174
165
|
filter(predicate: (value: T, index: number, array: readonly T[]) => unknown): T[];
|
|
175
166
|
reduce<U>(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: readonly T[]) => U, initialValue: U): U;
|
|
176
167
|
find(predicate: (value: T, index: number, array: readonly T[]) => unknown): T | undefined;
|
|
177
|
-
findIndex(predicate: (value: T, index: number, array: readonly T[]) => unknown):
|
|
168
|
+
findIndex(predicate: (value: T, index: number, array: readonly T[]) => unknown): int;
|
|
178
169
|
includes(searchElement: T, fromIndex?: number): boolean;
|
|
179
170
|
concat(...items: (T | readonly T[])[]): T[];
|
|
180
171
|
join(separator?: string): string;
|
|
@@ -198,7 +189,7 @@ declare global {
|
|
|
198
189
|
/**
|
|
199
190
|
* Returns the length of a String object.
|
|
200
191
|
*/
|
|
201
|
-
readonly length:
|
|
192
|
+
readonly length: int;
|
|
202
193
|
|
|
203
194
|
/**
|
|
204
195
|
* Returns the character at the specified index.
|
|
@@ -218,12 +209,12 @@ declare global {
|
|
|
218
209
|
/**
|
|
219
210
|
* Returns the position of the first occurrence of a substring.
|
|
220
211
|
*/
|
|
221
|
-
indexOf(searchString: string, position?: number):
|
|
212
|
+
indexOf(searchString: string, position?: number): int;
|
|
222
213
|
|
|
223
214
|
/**
|
|
224
215
|
* Returns the last occurrence of a substring in the string.
|
|
225
216
|
*/
|
|
226
|
-
lastIndexOf(searchString: string, position?: number):
|
|
217
|
+
lastIndexOf(searchString: string, position?: number): int;
|
|
227
218
|
|
|
228
219
|
/**
|
|
229
220
|
* Determines whether a string contains another string.
|
|
@@ -313,7 +304,7 @@ declare global {
|
|
|
313
304
|
/**
|
|
314
305
|
* Searches for a match in a string, and returns the index.
|
|
315
306
|
*/
|
|
316
|
-
search(regexp: RegExp):
|
|
307
|
+
search(regexp: RegExp): int;
|
|
317
308
|
}
|
|
318
309
|
|
|
319
310
|
interface StringConstructor {
|
|
@@ -390,7 +381,7 @@ declare global {
|
|
|
390
381
|
*/
|
|
391
382
|
interface Function {
|
|
392
383
|
prototype: any;
|
|
393
|
-
readonly length:
|
|
384
|
+
readonly length: int;
|
|
394
385
|
call(thisArg: any, ...argArray: any[]): any;
|
|
395
386
|
apply(thisArg: any, argArray?: any): any;
|
|
396
387
|
bind(thisArg: any, ...argArray: any[]): any;
|
|
@@ -611,12 +602,12 @@ declare global {
|
|
|
611
602
|
*/
|
|
612
603
|
interface IArguments {
|
|
613
604
|
[index: number]: any;
|
|
614
|
-
length:
|
|
605
|
+
length: int;
|
|
615
606
|
callee: Function;
|
|
616
607
|
}
|
|
617
608
|
|
|
618
609
|
interface ArrayLike<T> {
|
|
619
|
-
readonly length:
|
|
610
|
+
readonly length: int;
|
|
620
611
|
readonly [n: number]: T;
|
|
621
612
|
}
|
|
622
613
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsonic/js-globals",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Global type definitions for Tsonic JS mode (noLib: true, JavaScript semantics)",
|
|
5
5
|
"main": "index.d.ts",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -8,6 +8,15 @@
|
|
|
8
8
|
"index.d.ts",
|
|
9
9
|
"README.md"
|
|
10
10
|
],
|
|
11
|
+
"scripts": {
|
|
12
|
+
"typecheck": "tsc --noEmit"
|
|
13
|
+
},
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"@tsonic/types": "^0.3.0"
|
|
16
|
+
},
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"typescript": "^5.0.0"
|
|
19
|
+
},
|
|
11
20
|
"keywords": [
|
|
12
21
|
"tsonic",
|
|
13
22
|
"typescript",
|