From 7d5e7e50d0515771b876764ba1911530fce273fe Mon Sep 17 00:00:00 2001 From: Junxiao Shi Date: Sun, 26 Apr 2020 09:17:22 -0400 Subject: [PATCH 1/3] multi-set: improve iterator typing --- multi-set.d.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/multi-set.d.ts b/multi-set.d.ts index 2c9e811c..0e40bc40 100644 --- a/multi-set.d.ts +++ b/multi-set.d.ts @@ -23,10 +23,10 @@ export default class MultiSet implements Iterable { top(n: number): Array<[K, number]>; forEach(callback: (value: K, key: K, set: this) => void, scope?: any): void; forEachMultiplicity(callback: (value: number, key: K, set: this) => void, scope?: any): void; - keys(): Iterator; - values(): Iterator; - multiplicities(): Iterator<[K, number]>; - [Symbol.iterator](): Iterator; + keys(): IterableIterator; + values(): IterableIterator; + multiplicities(): IterableIterator<[K, number]>; + [Symbol.iterator](): IterableIterator; inspect(): any; toJSON(): any; From f48f918ea7b5b1f403aec56627e184e07cce375b Mon Sep 17 00:00:00 2001 From: Junxiao Shi Date: Sun, 26 Apr 2020 12:53:22 -0400 Subject: [PATCH 2/3] typings: improve iterator typing --- bi-map.d.ts | 16 ++++++++-------- bit-set.d.ts | 6 +++--- bit-vector.d.ts | 6 +++--- circular-buffer.d.ts | 6 +++--- default-map.d.ts | 8 ++++---- fixed-deque.d.ts | 6 +++--- fixed-stack.d.ts | 6 +++--- fuzzy-map.d.ts | 4 ++-- fuzzy-multi-map.d.ts | 4 ++-- inverted-index.d.ts | 6 +++--- linked-list.d.ts | 6 +++--- lru-cache.d.ts | 8 ++++---- lru-map.d.ts | 8 ++++---- passjoin-index.d.ts | 4 ++-- queue.d.ts | 6 +++--- sparse-map.d.ts | 8 ++++---- sparse-queue-set.d.ts | 4 ++-- sparse-set.d.ts | 4 ++-- stack.d.ts | 6 +++--- trie-map.d.ts | 10 +++++----- trie.d.ts | 6 +++--- vector.d.ts | 12 ++++++------ 22 files changed, 75 insertions(+), 75 deletions(-) diff --git a/bi-map.d.ts b/bi-map.d.ts index 297ce5fe..d0c2f766 100644 --- a/bi-map.d.ts +++ b/bi-map.d.ts @@ -15,10 +15,10 @@ export class InverseMap implements Iterable<[K, V]> { has(key: K): boolean; get(key: K): V; forEach(callback: (value: V, key: K, map: this) => void, scope?: any): void; - keys(): Iterator; - values(): Iterator; - entries(): Iterator<[K, V]>; - [Symbol.iterator](): Iterator<[K, V]>; + keys(): IterableIterator; + values(): IterableIterator; + entries(): IterableIterator<[K, V]>; + [Symbol.iterator](): IterableIterator<[K, V]>; inspect(): any; } @@ -35,10 +35,10 @@ export default class BiMap implements Iterable<[K, V]> { has(key: K): boolean; get(key: K): V; forEach(callback: (value: V, key: K, map: this) => void, scope?: any): void; - keys(): Iterator; - values(): Iterator; - entries(): Iterator<[K, V]>; - [Symbol.iterator](): Iterator<[K, V]>; + keys(): IterableIterator; + values(): IterableIterator; + entries(): IterableIterator<[K, V]>; + [Symbol.iterator](): IterableIterator<[K, V]>; inspect(): any; // Statics diff --git a/bit-set.d.ts b/bit-set.d.ts index 1a948d33..cfeb0d16 100644 --- a/bit-set.d.ts +++ b/bit-set.d.ts @@ -21,9 +21,9 @@ export default class BitSet implements Iterable { rank(r: number): number; select(r: number): number; forEach(callback: (index: number, value: number, set: this) => void, scope?: any): void; - values(): Iterator; - entries(): Iterator<[number, number]>; - [Symbol.iterator](): Iterator; + values(): IterableIterator; + entries(): IterableIterator<[number, number]>; + [Symbol.iterator](): IterableIterator; inspect(): any; toJSON(): Array; } diff --git a/bit-vector.d.ts b/bit-vector.d.ts index f51ebc81..4005d3c1 100644 --- a/bit-vector.d.ts +++ b/bit-vector.d.ts @@ -34,9 +34,9 @@ export default class BitVector implements Iterable { rank(r: number): number; select(r: number): number; forEach(callback: (index: number, value: number, set: this) => void, scope?: any): void; - values(): Iterator; - entries(): Iterator<[number, number]>; - [Symbol.iterator](): Iterator; + values(): IterableIterator; + entries(): IterableIterator<[number, number]>; + [Symbol.iterator](): IterableIterator; inspect(): any; toJSON(): Array; } diff --git a/circular-buffer.d.ts b/circular-buffer.d.ts index 66fd53f8..ec1fa4cb 100644 --- a/circular-buffer.d.ts +++ b/circular-buffer.d.ts @@ -24,9 +24,9 @@ export default class CircularBuffer implements Iterable { get(index: number): T | undefined; forEach(callback: (item: T, index: number, buffer: this) => void, scope?: any): void; toArray(): Iterable; - values(): Iterator; - entries(): Iterator<[number, T]>; - [Symbol.iterator](): Iterator; + values(): IterableIterator; + entries(): IterableIterator<[number, T]>; + [Symbol.iterator](): IterableIterator; inspect(): any; // Statics diff --git a/default-map.d.ts b/default-map.d.ts index 18377d6a..40e02608 100644 --- a/default-map.d.ts +++ b/default-map.d.ts @@ -18,10 +18,10 @@ export default class DefaultMap implements Iterable<[K, V]> { get(key: K): V | undefined; peek(key: K): V | undefined; forEach(callback: (value: V, key: K, map: this) => void, scope?: any): void; - keys(): Iterator; - values(): Iterator; - entries(): Iterator<[K, V]>; - [Symbol.iterator](): Iterator<[K, V]>; + keys(): IterableIterator; + values(): IterableIterator; + entries(): IterableIterator<[K, V]>; + [Symbol.iterator](): IterableIterator<[K, V]>; inspect(): any; // Statics diff --git a/fixed-deque.d.ts b/fixed-deque.d.ts index f87bacd1..6e6b9084 100644 --- a/fixed-deque.d.ts +++ b/fixed-deque.d.ts @@ -24,9 +24,9 @@ export default class FixedDeque implements Iterable { get(index: number): T | undefined; forEach(callback: (item: T, index: number, buffer: this) => void, scope?: any): void; toArray(): Iterable; - values(): Iterator; - entries(): Iterator<[number, T]>; - [Symbol.iterator](): Iterator; + values(): IterableIterator; + entries(): IterableIterator<[number, T]>; + [Symbol.iterator](): IterableIterator; inspect(): any; // Statics diff --git a/fixed-stack.d.ts b/fixed-stack.d.ts index a1cbf4ed..99658534 100644 --- a/fixed-stack.d.ts +++ b/fixed-stack.d.ts @@ -20,9 +20,9 @@ export default class FixedStack implements Iterable { peek(): T | undefined; forEach(callback: (item: T, index: number, stack: this) => void, scope?: any): void; toArray(): Iterable; - values(): Iterator; - entries(): Iterator<[number, T]>; - [Symbol.iterator](): Iterator; + values(): IterableIterator; + entries(): IterableIterator<[number, T]>; + [Symbol.iterator](): IterableIterator; toString(): string; toJSON(): Iterable; inspect(): any; diff --git a/fuzzy-map.d.ts b/fuzzy-map.d.ts index b33a8b35..7a1644dc 100644 --- a/fuzzy-map.d.ts +++ b/fuzzy-map.d.ts @@ -21,8 +21,8 @@ export default class FuzzyMap implements Iterable { get(key: any): V | undefined; has(key: any): boolean; forEach(callback: (value: V, key: V) => void, scope?: this): void; - values(): Iterator; - [Symbol.iterator](): Iterator; + values(): IterableIterator; + [Symbol.iterator](): IterableIterator; inspect(): any; // Statics diff --git a/fuzzy-multi-map.d.ts b/fuzzy-multi-map.d.ts index 83dce7d9..62b8250e 100644 --- a/fuzzy-multi-map.d.ts +++ b/fuzzy-multi-map.d.ts @@ -23,8 +23,8 @@ export default class FuzzyMultiMap implements Iterable { get(key: any): Array | Set | undefined; has(key: any): boolean; forEach(callback: (value: V, key: V) => void, scope?: any): void; - values(): Iterator; - [Symbol.iterator](): Iterator; + values(): IterableIterator; + [Symbol.iterator](): IterableIterator; inspect(): any; // Statics diff --git a/inverted-index.d.ts b/inverted-index.d.ts index 0d9aa258..4596ff83 100644 --- a/inverted-index.d.ts +++ b/inverted-index.d.ts @@ -20,9 +20,9 @@ export default class InvertedIndex implements Iterable { add(document: D): this; get(query: any): Array; forEach(callback: (document: D, index: number, invertedIndex: this) => void, scope?: any): void; - documents(): Iterator; - tokens(): Iterator; - [Symbol.iterator](): Iterator; + documents(): IterableIterator; + tokens(): IterableIterator; + [Symbol.iterator](): IterableIterator; inspect(): any; // Statics diff --git a/linked-list.d.ts b/linked-list.d.ts index 3e5e4d39..4eec48c7 100644 --- a/linked-list.d.ts +++ b/linked-list.d.ts @@ -17,9 +17,9 @@ export default class LinkedList implements Iterable { unshift(value: T): number; forEach(callback: (value: T, index: number, list: this) => void, scope?: any): void; toArray(): Array; - values(): Iterator; - entries(): Iterator<[number, T]>; - [Symbol.iterator](): Iterator; + values(): IterableIterator; + entries(): IterableIterator<[number, T]>; + [Symbol.iterator](): IterableIterator; toString(): string; toJSON(): Array; inspect(): any; diff --git a/lru-cache.d.ts b/lru-cache.d.ts index 7369b7b7..45b61e0b 100644 --- a/lru-cache.d.ts +++ b/lru-cache.d.ts @@ -22,10 +22,10 @@ export default class LRUCache implements Iterable<[K, V]> { peek(key: K): V | undefined; has(key: K): boolean; forEach(callback: (value: V, key: K, cache: this) => void, scope?: any): void; - keys(): Iterator; - values(): Iterator; - entries(): Iterator<[K, V]>; - [Symbol.iterator](): Iterator<[K, V]>; + keys(): IterableIterator; + values(): IterableIterator; + entries(): IterableIterator<[K, V]>; + [Symbol.iterator](): IterableIterator<[K, V]>; inspect(): any; // Statics diff --git a/lru-map.d.ts b/lru-map.d.ts index b48baa5e..0943543a 100644 --- a/lru-map.d.ts +++ b/lru-map.d.ts @@ -22,10 +22,10 @@ export default class LRUMap implements Iterable<[K, V]> { peek(key: K): V | undefined; has(key: K): boolean; forEach(callback: (value: V, key: K, cache: this) => void, scope?: any): void; - keys(): Iterator; - values(): Iterator; - entries(): Iterator<[K, V]>; - [Symbol.iterator](): Iterator<[K, V]>; + keys(): IterableIterator; + values(): IterableIterator; + entries(): IterableIterator<[K, V]>; + [Symbol.iterator](): IterableIterator<[K, V]>; inspect(): any; // Statics diff --git a/passjoin-index.d.ts b/passjoin-index.d.ts index fa539f54..4d917467 100644 --- a/passjoin-index.d.ts +++ b/passjoin-index.d.ts @@ -17,8 +17,8 @@ export default class PassjoinIndex implements Iterable { search(query: T): Set; clear(): void; forEach(callback: (value: T, index: number, self: this) => void, scope?: any): void; - values(): Iterator; - [Symbol.iterator](): Iterator; + values(): IterableIterator; + [Symbol.iterator](): IterableIterator; inspect(): any; // Statics diff --git a/queue.d.ts b/queue.d.ts index 955239d9..2d3e4345 100644 --- a/queue.d.ts +++ b/queue.d.ts @@ -14,9 +14,9 @@ export default class Queue implements Iterable { peek(): T | undefined; forEach(callback: (item: T, index: number, queue: this) => void, scope?: any): void; toArray(): Array; - values(): Iterator; - entries(): Iterator<[number, T]>; - [Symbol.iterator](): Iterator; + values(): IterableIterator; + entries(): IterableIterator<[number, T]>; + [Symbol.iterator](): IterableIterator; toString(): string; toJSON(): Array; inspect(): any; diff --git a/sparse-map.d.ts b/sparse-map.d.ts index 8e042907..0b22f905 100644 --- a/sparse-map.d.ts +++ b/sparse-map.d.ts @@ -18,9 +18,9 @@ export default class SparseMap implements Iterable<[number, V]> { set(key: number, value: V): this; delete(key: number): boolean; forEach(callback: (value: V, key: number, set: this) => void, scope?: any): void; - keys(): Iterator; - values(): Iterator; - entries(): Iterator<[number, V]>; - [Symbol.iterator](): Iterator<[number, V]>; + keys(): IterableIterator; + values(): IterableIterator; + entries(): IterableIterator<[number, V]>; + [Symbol.iterator](): IterableIterator<[number, V]>; inspect(): any; } diff --git a/sparse-queue-set.d.ts b/sparse-queue-set.d.ts index c8693bed..e7463bf0 100644 --- a/sparse-queue-set.d.ts +++ b/sparse-queue-set.d.ts @@ -18,7 +18,7 @@ export default class SparseQueueSet implements Iterable { enqueue(value: number): this; dequeue(): number | undefined; forEach(callback: (value: number, key: number, set: this) => void, scope?: any): void; - values(): Iterator; - [Symbol.iterator](): Iterator; + values(): IterableIterator; + [Symbol.iterator](): IterableIterator; inspect(): any; } diff --git a/sparse-set.d.ts b/sparse-set.d.ts index 642c599d..99fe655e 100644 --- a/sparse-set.d.ts +++ b/sparse-set.d.ts @@ -17,7 +17,7 @@ export default class SparseSet implements Iterable { add(value: number): this; delete(value: number): boolean; forEach(callback: (value: number, key: number, set: this) => void, scope?: any): void; - values(): Iterator; - [Symbol.iterator](): Iterator; + values(): IterableIterator; + [Symbol.iterator](): IterableIterator; inspect(): any; } diff --git a/stack.d.ts b/stack.d.ts index a446843a..fa6998b4 100644 --- a/stack.d.ts +++ b/stack.d.ts @@ -14,9 +14,9 @@ export default class Stack implements Iterable { peek(): T | undefined; forEach(callback: (item: T, index: number, stack: this) => void, scope?: any): void; toArray(): Array; - values(): Iterator; - entries(): Iterator<[number, T]>; - [Symbol.iterator](): Iterator; + values(): IterableIterator; + entries(): IterableIterator<[number, T]>; + [Symbol.iterator](): IterableIterator; toString(): string; toJSON(): Array; inspect(): any; diff --git a/trie-map.d.ts b/trie-map.d.ts index 9566f8ef..af889890 100644 --- a/trie-map.d.ts +++ b/trie-map.d.ts @@ -17,11 +17,11 @@ export default class TrieMap implements Iterable<[K, V]> { delete(prefix: K): boolean; has(prefix: K): boolean; find(prefix: K): Array<[K, V]>; - values(): Iterator; - prefixes(): Iterator; - keys(): Iterator; - entries(): Iterator<[K, V]>; - [Symbol.iterator](): Iterator<[K, V]>; + values(): IterableIterator; + prefixes(): IterableIterator; + keys(): IterableIterator; + entries(): IterableIterator<[K, V]>; + [Symbol.iterator](): IterableIterator<[K, V]>; inspect(): any; // Statics diff --git a/trie.d.ts b/trie.d.ts index 37f25cc7..4b2a202e 100644 --- a/trie.d.ts +++ b/trie.d.ts @@ -16,9 +16,9 @@ export default class Trie implements Iterable { delete(prefix: T): boolean; has(prefix: T): boolean; find(prefix: T): Array; - prefixes(): Iterator; - keys(): Iterator; - [Symbol.iterator](): Iterator; + prefixes(): IterableIterator; + keys(): IterableIterator; + [Symbol.iterator](): IterableIterator; inspect(): any; // Statics diff --git a/vector.d.ts b/vector.d.ts index d2861154..414f9694 100644 --- a/vector.d.ts +++ b/vector.d.ts @@ -30,9 +30,9 @@ export default class Vector implements Iterable { pop(): number | undefined; get(index: number): number; forEach(callback: (index: number, value: number, set: this) => void, scope?: any): void; - values(): Iterator; - entries(): Iterator<[number, number]>; - [Symbol.iterator](): Iterator; + values(): IterableIterator; + entries(): IterableIterator<[number, number]>; + [Symbol.iterator](): IterableIterator; inspect(): any; toJSON(): any; @@ -60,9 +60,9 @@ declare class TypedVector implements Iterable { pop(): number | undefined; get(index: number): number; forEach(callback: (index: number, value: number, set: this) => void, scope?: any): void; - values(): Iterator; - entries(): Iterator<[number, number]>; - [Symbol.iterator](): Iterator; + values(): IterableIterator; + entries(): IterableIterator<[number, number]>; + [Symbol.iterator](): IterableIterator; inspect(): any; toJSON(): any; From 99680cff4f64c4b1a319f83618958bbb036791f6 Mon Sep 17 00:00:00 2001 From: Junxiao Shi Date: Sun, 26 Apr 2020 13:35:37 -0400 Subject: [PATCH 3/3] default-map: get() cannot return undefined --- default-map.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/default-map.d.ts b/default-map.d.ts index 40e02608..c0cf3f38 100644 --- a/default-map.d.ts +++ b/default-map.d.ts @@ -15,7 +15,7 @@ export default class DefaultMap implements Iterable<[K, V]> { set(key: K, value: V): this; delete(key: K): boolean; has(key: K): boolean; - get(key: K): V | undefined; + get(key: K): V; peek(key: K): V | undefined; forEach(callback: (value: V, key: K, map: this) => void, scope?: any): void; keys(): IterableIterator;