From 33da0daffb4d4f03ec0623e4d31fdd8c387962ae Mon Sep 17 00:00:00 2001 From: Zev Spitz Date: Wed, 30 May 2018 01:54:20 +0300 Subject: [PATCH] [activex-*] Remove Enumerator overload taking SafeArray (#26103) * Remove enumerator overload that takes SafeArray * Interop tests depend on activex-scripting; associated version bump * windows-script-host version bump * npm test fixes * Fix comment --- types/activex-diskquota/index.d.ts | 2 +- types/activex-excel/activex-excel-tests.ts | 8 ++- .../activex-faxcomexlib-tests.ts | 4 +- .../activex-interop/activex-interop-tests.ts | 49 ++++--------------- types/activex-interop/index.d.ts | 6 +-- types/activex-iwshruntimelibrary/index.d.ts | 2 +- types/activex-libreoffice/index.d.ts | 2 +- types/activex-mshtml/index.d.ts | 2 +- types/activex-msxml2/index.d.ts | 2 +- types/activex-scripting/index.d.ts | 6 ++- types/windows-script-host/index.d.ts | 2 +- 11 files changed, 33 insertions(+), 52 deletions(-) diff --git a/types/activex-diskquota/index.d.ts b/types/activex-diskquota/index.d.ts index da7457e066..71b534ee0c 100644 --- a/types/activex-diskquota/index.d.ts +++ b/types/activex-diskquota/index.d.ts @@ -2,7 +2,7 @@ // Project: https://msdn.microsoft.com/en-us/library/windows/desktop/bb773938(v=vs.85).aspx // Definitions by: Zev Spitz // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.5 +// TypeScript Version: 2.6 /// diff --git a/types/activex-excel/activex-excel-tests.ts b/types/activex-excel/activex-excel-tests.ts index 78291d57b5..4f6fab3aa1 100644 --- a/types/activex-excel/activex-excel-tests.ts +++ b/types/activex-excel/activex-excel-tests.ts @@ -296,11 +296,17 @@ const setColumnVisibility = (visible: boolean) => { const combobox = sheet.OLEObjects('ComboBox1').Object as MSForms.ComboBox; combobox.Clear(); - const enumerator = new Enumerator(dict.Items()); + + // iterate over keys using Enumerator + const enumerator = new Enumerator(dict); enumerator.moveFirst(); while (!enumerator.atEnd()) { combobox.AddItem(enumerator.item()); + enumerator.moveNext(); } + + // alternatively, make a JS array out of the keys, and iterate using forEach + // new VBArray(dict.Keys()).toArray().forEach(x => combobox.AddItem(x)); })(); })(); diff --git a/types/activex-faxcomexlib/activex-faxcomexlib-tests.ts b/types/activex-faxcomexlib/activex-faxcomexlib-tests.ts index 478e816eb7..ae9edbe8c9 100644 --- a/types/activex-faxcomexlib/activex-faxcomexlib-tests.ts +++ b/types/activex-faxcomexlib/activex-faxcomexlib-tests.ts @@ -1,7 +1,7 @@ /// /// -const collectionToArray = (col: { Item(index: any): T } | SafeArray) => { +const collectionToArray = (col: { Item(index: any): T }): T[] => { const results: T[] = []; const enumerator = new Enumerator(col); enumerator.moveFirst(); @@ -423,7 +423,7 @@ the job? document.GroupBroadcastReceipts = true; const jobIDs = document.Submit(''); - collectionToArray(jobIDs).forEach(jobID => WScript.Echo(`The job ID is ${jobID}`)); + new VBArray(jobIDs).toArray().forEach(jobID => WScript.Echo(`The job ID is ${jobID}`)); while (recipients.Count > 0) { recipients.Remove(1); diff --git a/types/activex-interop/activex-interop-tests.ts b/types/activex-interop/activex-interop-tests.ts index e2ece7401e..06c73aa952 100644 --- a/types/activex-interop/activex-interop-tests.ts +++ b/types/activex-interop/activex-interop-tests.ts @@ -1,49 +1,20 @@ -// copied from the definitions in activex-scripting -interface Dictionary { - /** 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; - - /** Change a key to a different key. */ - Key(Key: TKey): TKey; - - /** Get an array containing all keys in the dictionary. */ - Keys(): SafeArray; - - /** 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 = new ActiveXObject('Scripting.Dictionary'); +const dict: Scripting.Dictionary = new ActiveXObject('Scripting.Dictionary'); dict.Add('one', 1); dict.Add('two', 2); dict.Add('three', 3); -const keyEnumerator = new Enumerator(dict.Keys()); +const keyEnumerator = new Enumerator(dict); keyEnumerator.moveFirst(); while (!keyEnumerator.atEnd()) { const item = dict(keyEnumerator.item()); const power = Math.pow(item, 2); } + +const keysArray = new VBArray(dict.Keys()).toArray(); +const itemsArray = new VBArray(dict.Items()).toArray(); +for (let i = 0; i < keysArray.length; i++) { + const key = keysArray[i]; + const item = itemsArray[i]; +} diff --git a/types/activex-interop/index.d.ts b/types/activex-interop/index.d.ts index caa74fff38..3bb13a5351 100644 --- a/types/activex-interop/index.d.ts +++ b/types/activex-interop/index.d.ts @@ -2,7 +2,7 @@ // Project: https://msdn.microsoft.com/en-us/library/ff521046(v=vs.85).aspx // Definitions by: Zev Spitz // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.3 +// TypeScript Version: 2.6 // tslint:disable-next-line no-empty-interface interface ActiveXObjectNameMap { } @@ -50,8 +50,8 @@ interface Enumerator { } interface EnumeratorConstructor { - new (collection: SafeArray | { Item(index: any): T }): Enumerator; - new (collection: any): Enumerator; + new (collection: { Item(index: any): T }): Enumerator; + // new (collection: any): Enumerator; } declare var Enumerator: EnumeratorConstructor; diff --git a/types/activex-iwshruntimelibrary/index.d.ts b/types/activex-iwshruntimelibrary/index.d.ts index 1f89c2b84a..fad992e185 100644 --- a/types/activex-iwshruntimelibrary/index.d.ts +++ b/types/activex-iwshruntimelibrary/index.d.ts @@ -2,7 +2,7 @@ // Project: https://msdn.microsoft.com/en-us/library/9bbdkx3k.aspx // Definitions by: Zev Spitz // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.3 +// TypeScript Version: 2.6 /// diff --git a/types/activex-libreoffice/index.d.ts b/types/activex-libreoffice/index.d.ts index 3459215083..7d8e109861 100644 --- a/types/activex-libreoffice/index.d.ts +++ b/types/activex-libreoffice/index.d.ts @@ -2,7 +2,7 @@ // Project: https://api.libreoffice.org/ // Definitions by: Zev Spitz // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.3 +// TypeScript Version: 2.6 /// diff --git a/types/activex-mshtml/index.d.ts b/types/activex-mshtml/index.d.ts index b2f8a92883..93b307d3ba 100644 --- a/types/activex-mshtml/index.d.ts +++ b/types/activex-mshtml/index.d.ts @@ -2,7 +2,7 @@ // Project: https://msdn.microsoft.com/en-us/library/aa741317(v=vs.85).aspx // Definitions by: Zev Spitz // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.3 +// TypeScript Version: 2.6 declare namespace MSHTML { const enum _BEHAVIOR_EVENT { diff --git a/types/activex-msxml2/index.d.ts b/types/activex-msxml2/index.d.ts index 5353864443..3ee2b1f050 100644 --- a/types/activex-msxml2/index.d.ts +++ b/types/activex-msxml2/index.d.ts @@ -2,7 +2,7 @@ // Project: https://msdn.microsoft.com/en-us/library/ms763742.aspx // Definitions by: Zev Spitz // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.3 +// TypeScript Version: 2.6 /// diff --git a/types/activex-scripting/index.d.ts b/types/activex-scripting/index.d.ts index e0f8ba306d..0d2ae52343 100644 --- a/types/activex-scripting/index.d.ts +++ b/types/activex-scripting/index.d.ts @@ -491,7 +491,7 @@ declare namespace Scripting { } interface ActiveXObject { - set(obj: Scripting.Dictionary, propertyName: 'Item', parameterTypes: [any], newValue: any): void; + set(obj: Scripting.Dictionary, propertyName: 'Item', parameterTypes: [TKey], newValue: TValue): void; } interface ActiveXObjectNameMap { @@ -499,3 +499,7 @@ interface ActiveXObjectNameMap { 'Scripting.Encoder': Scripting.Encoder; 'Scripting.FileSystemObject': Scripting.FileSystemObject; } + +interface EnumeratorConstructor { + new (dict: Scripting.Dictionary): Enumerator; +} diff --git a/types/windows-script-host/index.d.ts b/types/windows-script-host/index.d.ts index 47f11e4d39..a6be9a0e4c 100644 --- a/types/windows-script-host/index.d.ts +++ b/types/windows-script-host/index.d.ts @@ -2,7 +2,7 @@ // Project: https://msdn.microsoft.com/en-us/library/9bbdkx3k.aspx // Definitions by: Zev Spitz // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.3 +// TypeScript Version: 2.6 ///