@tsonic/js-globals 0.1.0 → 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.
Files changed (2) hide show
  1. package/index.d.ts +22 -32
  2. package/package.json +10 -1
package/index.d.ts CHANGED
@@ -8,24 +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
- 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;
16
+ import { int } from "@tsonic/types";
28
17
 
18
+ declare global {
29
19
  /**
30
20
  * Array type with full JavaScript API
31
21
  * In JS mode, these compile to Tsonic.JSRuntime extension methods
@@ -34,7 +24,7 @@ declare global {
34
24
  /**
35
25
  * Gets or sets the length of the array.
36
26
  */
37
- length: number;
27
+ length: int;
38
28
 
39
29
  /**
40
30
  * Returns the item located at the specified index.
@@ -44,7 +34,7 @@ declare global {
44
34
  /**
45
35
  * Appends new elements to the end of an array, and returns the new length.
46
36
  */
47
- push(...items: T[]): number;
37
+ push(...items: T[]): int;
48
38
 
49
39
  /**
50
40
  * Removes the last element from an array and returns it.
@@ -59,7 +49,7 @@ declare global {
59
49
  /**
60
50
  * Inserts new elements at the start of an array, and returns the new length.
61
51
  */
62
- unshift(...items: T[]): number;
52
+ unshift(...items: T[]): int;
63
53
 
64
54
  /**
65
55
  * Returns a copy of a section of an array.
@@ -74,12 +64,12 @@ declare global {
74
64
  /**
75
65
  * Returns the index of the first occurrence of a value in an array, or -1 if it is not present.
76
66
  */
77
- indexOf(searchElement: T, fromIndex?: number): number;
67
+ indexOf(searchElement: T, fromIndex?: number): int;
78
68
 
79
69
  /**
80
70
  * Returns the index of the last occurrence of a specified value in an array, or -1 if it is not present.
81
71
  */
82
- lastIndexOf(searchElement: T, fromIndex?: number): number;
72
+ lastIndexOf(searchElement: T, fromIndex?: number): int;
83
73
 
84
74
  /**
85
75
  * Determines whether all the members of an array satisfy the specified test.
@@ -119,7 +109,7 @@ declare global {
119
109
  /**
120
110
  * Returns the index of the first element in the array where predicate is true, and -1 otherwise.
121
111
  */
122
- findIndex(predicate: (value: T, index: number, array: T[]) => unknown): number;
112
+ findIndex(predicate: (value: T, index: number, array: T[]) => unknown): int;
123
113
 
124
114
  /**
125
115
  * Determines whether an array includes a certain element.
@@ -163,11 +153,11 @@ declare global {
163
153
  }
164
154
 
165
155
  interface ReadonlyArray<T> {
166
- readonly length: number;
156
+ readonly length: int;
167
157
  readonly [n: number]: T;
168
158
  slice(start?: number, end?: number): T[];
169
- indexOf(searchElement: T, fromIndex?: number): number;
170
- lastIndexOf(searchElement: T, fromIndex?: number): number;
159
+ indexOf(searchElement: T, fromIndex?: number): int;
160
+ lastIndexOf(searchElement: T, fromIndex?: number): int;
171
161
  every(predicate: (value: T, index: number, array: readonly T[]) => unknown): boolean;
172
162
  some(predicate: (value: T, index: number, array: readonly T[]) => unknown): boolean;
173
163
  forEach(callbackfn: (value: T, index: number, array: readonly T[]) => void): void;
@@ -175,7 +165,7 @@ declare global {
175
165
  filter(predicate: (value: T, index: number, array: readonly T[]) => unknown): T[];
176
166
  reduce<U>(callbackfn: (previousValue: U, currentValue: T, currentIndex: number, array: readonly T[]) => U, initialValue: U): U;
177
167
  find(predicate: (value: T, index: number, array: readonly T[]) => unknown): T | undefined;
178
- findIndex(predicate: (value: T, index: number, array: readonly T[]) => unknown): number;
168
+ findIndex(predicate: (value: T, index: number, array: readonly T[]) => unknown): int;
179
169
  includes(searchElement: T, fromIndex?: number): boolean;
180
170
  concat(...items: (T | readonly T[])[]): T[];
181
171
  join(separator?: string): string;
@@ -199,7 +189,7 @@ declare global {
199
189
  /**
200
190
  * Returns the length of a String object.
201
191
  */
202
- readonly length: number;
192
+ readonly length: int;
203
193
 
204
194
  /**
205
195
  * Returns the character at the specified index.
@@ -219,12 +209,12 @@ declare global {
219
209
  /**
220
210
  * Returns the position of the first occurrence of a substring.
221
211
  */
222
- indexOf(searchString: string, position?: number): number;
212
+ indexOf(searchString: string, position?: number): int;
223
213
 
224
214
  /**
225
215
  * Returns the last occurrence of a substring in the string.
226
216
  */
227
- lastIndexOf(searchString: string, position?: number): number;
217
+ lastIndexOf(searchString: string, position?: number): int;
228
218
 
229
219
  /**
230
220
  * Determines whether a string contains another string.
@@ -314,7 +304,7 @@ declare global {
314
304
  /**
315
305
  * Searches for a match in a string, and returns the index.
316
306
  */
317
- search(regexp: RegExp): number;
307
+ search(regexp: RegExp): int;
318
308
  }
319
309
 
320
310
  interface StringConstructor {
@@ -391,7 +381,7 @@ declare global {
391
381
  */
392
382
  interface Function {
393
383
  prototype: any;
394
- readonly length: number;
384
+ readonly length: int;
395
385
  call(thisArg: any, ...argArray: any[]): any;
396
386
  apply(thisArg: any, argArray?: any): any;
397
387
  bind(thisArg: any, ...argArray: any[]): any;
@@ -612,12 +602,12 @@ declare global {
612
602
  */
613
603
  interface IArguments {
614
604
  [index: number]: any;
615
- length: number;
605
+ length: int;
616
606
  callee: Function;
617
607
  }
618
608
 
619
609
  interface ArrayLike<T> {
620
- readonly length: number;
610
+ readonly length: int;
621
611
  readonly [n: number]: T;
622
612
  }
623
613
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsonic/js-globals",
3
- "version": "0.1.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",