Skip to content

Commit 8245597

Browse files
zspitzmhegazy
authored andcommitted
Adds VarDate and SafeArray<T> as pseudonominal types to lib.d.ts (#18566)
* SafeArray<T>; stronger typing for VarDate, and for VBArray and Enumerator constructors * Add overload to Enumerator based on Item method * Add return type to Enumerator constructor
1 parent b549e26 commit 8245597

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

src/lib/scripthost.d.ts

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -201,10 +201,18 @@ declare var WScript: {
201201
Sleep(intTime: number): void;
202202
};
203203

204+
/**
205+
* Represents an Automation SAFEARRAY
206+
*/
207+
declare class SafeArray<T = any> {
208+
private constructor();
209+
private SafeArray_typekey: SafeArray<T>;
210+
}
211+
204212
/**
205213
* Allows enumerating over a COM collection, which may not have indexed item access.
206214
*/
207-
interface Enumerator<T> {
215+
interface Enumerator<T = any> {
208216
/**
209217
* Returns true if the current item is the last one in the collection, or the collection is empty,
210218
* or the current item is undefined.
@@ -230,16 +238,17 @@ interface Enumerator<T> {
230238
}
231239

232240
interface EnumeratorConstructor {
233-
new <T>(collection: any): Enumerator<T>;
234-
new (collection: any): Enumerator<any>;
241+
new <T = any>(safearray: SafeArray<T>): Enumerator<T>;
242+
new <T = any>(collection: { Item(index: any): T }): Enumerator<T>;
243+
new <T = any>(collection: any): Enumerator<T>;
235244
}
236245

237246
declare var Enumerator: EnumeratorConstructor;
238247

239248
/**
240249
* Enables reading from a COM safe array, which might have an alternate lower bound, or multiple dimensions.
241250
*/
242-
interface VBArray<T> {
251+
interface VBArray<T = any> {
243252
/**
244253
* Returns the number of dimensions (1-based).
245254
*/
@@ -271,16 +280,18 @@ interface VBArray<T> {
271280
}
272281

273282
interface VBArrayConstructor {
274-
new <T>(safeArray: any): VBArray<T>;
275-
new (safeArray: any): VBArray<any>;
283+
new <T = any>(safeArray: SafeArray<T>): VBArray<T>;
276284
}
277285

278286
declare var VBArray: VBArrayConstructor;
279287

280288
/**
281289
* Automation date (VT_DATE)
282290
*/
283-
interface VarDate { }
291+
declare class VarDate {
292+
private constructor();
293+
private VarDate_typekey: VarDate;
294+
}
284295

285296
interface DateConstructor {
286297
new (vd: VarDate): Date;

0 commit comments

Comments
 (0)