Interop definitions -

https://github.com/Microsoft/TypeScript/issues/21440
This commit is contained in:
Zev Spitz
2018-05-10 16:37:44 +02:00
parent 8889c1c89c
commit 2016139475
4 changed files with 186 additions and 0 deletions

View File

@@ -0,0 +1,49 @@
// copied from the definitions in activex-scripting
interface Dictionary<TKey = any, TItem = any> {
/** Add a new key and item to the dictionary. */
Add(Key: TKey, Item: TItem): void;
/** Get the number of items in the dictionary. */
readonly Count: number;
/** Determine if a given key is in the dictionary. */
Exists(Key: TKey): boolean;
HashVal(Key: TKey): any;
/** Set or get the item for a given key */
Item(Key: TKey): TItem;
/** Get an array containing all items in the dictionary. */
Items(): SafeArray<TItem>;
/** Change a key to a different key. */
Key(Key: TKey): TKey;
/** Get an array containing all keys in the dictionary. */
Keys(): SafeArray<TKey>;
/** Remove a given key from the dictionary. */
Remove(Key: TKey): void;
/** Remove all information from the dictionary. */
RemoveAll(): void;
/** Set or get the item for a given key */
(Key: TKey): TItem;
}
interface ActiveXObjectNameMap {
'Scripting.Dictionary': Dictionary;
}
const dict: Dictionary<string, number> = new ActiveXObject('Scripting.Dictionary');
dict.Add('one', 1);
dict.Add('two', 2);
dict.Add('three', 3);
const keyEnumerator = new Enumerator(dict.Keys());
keyEnumerator.moveFirst();
while (!keyEnumerator.atEnd()) {
const item = dict(keyEnumerator.item());
const power = Math.pow(item, 2);
}

113
types/activex-interop/index.d.ts vendored Normal file
View File

@@ -0,0 +1,113 @@
// Type definitions for Javascript Automation interop 0.0
// Project: https://msdn.microsoft.com/en-us/library/ff521046(v=vs.85).aspx
// Definitions by: Zev Spitz <https://github.com/zspitz>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
// tslint:disable-next-line no-empty-interface
interface ActiveXObjectNameMap { }
interface ActiveXObject {
new <K extends keyof ActiveXObjectNameMap>(progid: K): ActiveXObjectNameMap[K];
new(s: string): any;
}
declare var ActiveXObject: ActiveXObject;
/**
* Represents an Automation SAFEARRAY
*/
declare class SafeArray<T = any> {
private constructor();
private SafeArray_typekey: SafeArray<T>;
}
/**
* Allows enumerating over a COM collection, which may not have indexed item access.
*/
interface Enumerator<T = any> {
/**
* Returns true if the current item is the last one in the collection, or the collection is empty,
* or the current item is undefined.
*/
atEnd(): boolean;
/**
* Returns the current item in the collection
*/
item(): T;
/**
* Resets the current item in the collection to the first item. If there are no items in the collection,
* the current item is set to undefined.
*/
moveFirst(): void;
/**
* Moves the current item to the next item in the collection. If the enumerator is at the end of
* the collection or the collection is empty, the current item is set to undefined.
*/
moveNext(): void;
}
interface EnumeratorConstructor {
new <T = any>(collection: SafeArray<T> | { Item(index: any): T }): Enumerator<T>;
new (collection: any): Enumerator;
}
declare var Enumerator: EnumeratorConstructor;
/**
* Enables reading from a COM safe array, which might have an alternate lower bound, or multiple dimensions.
*/
interface VBArray<T = any> {
/**
* Returns the number of dimensions (1-based).
*/
dimensions(): number;
/**
* Takes an index for each dimension in the array, and returns the item at the corresponding location.
*/
getItem(dimension1Index: number, ...dimensionNIndexes: number[]): T;
/**
* Returns the smallest available index for a given dimension.
* @param dimension 1-based dimension (defaults to 1)
*/
lbound(dimension?: number): number;
/**
* Returns the largest available index for a given dimension.
* @param dimension 1-based dimension (defaults to 1)
*/
ubound(dimension?: number): number;
/**
* Returns a Javascript array with all the elements in the VBArray. If there are multiple dimensions,
* each successive dimension is appended to the end of the array.
* Example: [[1,2,3],[4,5,6]] becomes [1,2,3,4,5,6]
*/
toArray(): T[];
}
interface VBArrayConstructor {
new <T = any>(safeArray: SafeArray<T>): VBArray<T>;
}
declare var VBArray: VBArrayConstructor;
/**
* Automation date (VT_DATE)
*/
declare class VarDate {
private constructor();
private VarDate_typekey: VarDate;
}
interface DateConstructor {
new(vd: VarDate): Date;
}
interface Date {
getVarDate: () => VarDate;
}

View File

@@ -0,0 +1,21 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es5"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [ "../"],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"activex-interop-tests.ts"
]
}

View File

@@ -0,0 +1,3 @@
{
"extends": "dtslint/dt.json"
}