From a3a2ff5f1286649043d51d4dd416ede5acc7ee83 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Tue, 22 Aug 2017 10:13:08 +0100 Subject: [PATCH 1/5] Optimize relations for type references with unconstrained type arguments --- src/compiler/checker.ts | 44 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index d2d3697f175c6..b179231736c3e 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -8805,8 +8805,7 @@ namespace ts { return true; } if (source.flags & TypeFlags.Object && target.flags & TypeFlags.Object) { - const id = relation !== identityRelation || source.id < target.id ? source.id + "," + target.id : target.id + "," + source.id; - const related = relation.get(id); + const related = relation.get(getRelationKey(source, target, relation)); if (related !== undefined) { return related === RelationComparisonResult.Succeeded; } @@ -9207,7 +9206,7 @@ namespace ts { if (overflow) { return Ternary.False; } - const id = relation !== identityRelation || source.id < target.id ? source.id + "," + target.id : target.id + "," + source.id; + const id = getRelationKey(source, target, relation); const related = relation.get(id); if (related !== undefined) { if (reportErrors && related === RelationComparisonResult.Failed) { @@ -9772,6 +9771,45 @@ namespace ts { } } + function isUnconstrainedTypeParameter(type: Type) { + return type.flags & TypeFlags.TypeParameter && !getConstraintFromTypeParameter(type); + } + + function isTypeReferenceWithGenericArguments(type: Type) { + return getObjectFlags(type) & ObjectFlags.Reference && some((type).typeArguments, isUnconstrainedTypeParameter); + } + + function getTypeReferenceId(type: TypeReference, typeParameters: Type[]) { + let result = "" + type.id; + for (const t of type.typeArguments) { + if (isUnconstrainedTypeParameter(t)) { + let index = indexOf(typeParameters, t); + if (index < 0) { + index = typeParameters.length; + typeParameters.push(t); + } + result += "=" + index; + } + else { + result += "-" + t.id; + } + } + return result; + } + + function getRelationKey(source: Type, target: Type, relation: Map) { + if (relation === identityRelation && source.id > target.id) { + const temp = source; + source = target; + target = temp; + } + if (isTypeReferenceWithGenericArguments(source) && isTypeReferenceWithGenericArguments(target)) { + const typeParameters: Type[] = []; + return getTypeReferenceId(source, typeParameters) + "," + getTypeReferenceId(target, typeParameters); + } + return source.id + "," + target.id; + } + // Invoke the callback for each underlying property symbol of the given symbol and return the first // value that isn't undefined. function forEachProperty(prop: Symbol, callback: (p: Symbol) => T): T { From 11c4c4cd61cbc2f0a42f7bd81e55bbf9b4c7a70f Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Tue, 22 Aug 2017 17:41:07 +0100 Subject: [PATCH 2/5] Fix to use correct target type ID --- src/compiler/checker.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index b179231736c3e..3accf1637386e 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -9780,7 +9780,7 @@ namespace ts { } function getTypeReferenceId(type: TypeReference, typeParameters: Type[]) { - let result = "" + type.id; + let result = "" + type.target.id; for (const t of type.typeArguments) { if (isUnconstrainedTypeParameter(t)) { let index = indexOf(typeParameters, t); From e27d0917c9d0a9d364f0cbbc67bf880f32fd8808 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Mon, 21 Aug 2017 10:09:21 -0700 Subject: [PATCH 3/5] Test performance improvement:nested reference skip --- .../complexRecursiveCollections.errors.txt | 847 ++++++++++++++++++ .../compiler/complexRecursiveCollections.ts | 532 +++++++++++ 2 files changed, 1379 insertions(+) create mode 100644 tests/baselines/reference/complexRecursiveCollections.errors.txt create mode 100644 tests/cases/compiler/complexRecursiveCollections.ts diff --git a/tests/baselines/reference/complexRecursiveCollections.errors.txt b/tests/baselines/reference/complexRecursiveCollections.errors.txt new file mode 100644 index 0000000000000..38f66b7456a7f --- /dev/null +++ b/tests/baselines/reference/complexRecursiveCollections.errors.txt @@ -0,0 +1,847 @@ +tests/cases/compiler/immutable.d.ts(25,39): error TS2304: Cannot find name 'Iterable'. +tests/cases/compiler/immutable.d.ts(46,20): error TS2304: Cannot find name 'Iterable'. +tests/cases/compiler/immutable.d.ts(47,23): error TS2304: Cannot find name 'Iterable'. +tests/cases/compiler/immutable.d.ts(48,23): error TS2304: Cannot find name 'Iterable'. +tests/cases/compiler/immutable.d.ts(49,23): error TS2304: Cannot find name 'Iterable'. +tests/cases/compiler/immutable.d.ts(50,23): error TS2304: Cannot find name 'Iterable'. +tests/cases/compiler/immutable.d.ts(51,22): error TS2304: Cannot find name 'Iterable'. +tests/cases/compiler/immutable.d.ts(52,26): error TS2304: Cannot find name 'Iterable'. +tests/cases/compiler/immutable.d.ts(58,45): error TS2304: Cannot find name 'Iterable'. +tests/cases/compiler/immutable.d.ts(60,63): error TS2304: Cannot find name 'Iterable'. +tests/cases/compiler/immutable.d.ts(68,41): error TS2304: Cannot find name 'Iterable'. +tests/cases/compiler/immutable.d.ts(69,38): error TS2304: Cannot find name 'Iterable'. +tests/cases/compiler/immutable.d.ts(69,47): error TS2304: Cannot find name 'Iterable'. +tests/cases/compiler/immutable.d.ts(78,21): error TS2304: Cannot find name 'Iterable'. +tests/cases/compiler/immutable.d.ts(79,21): error TS2304: Cannot find name 'Iterable'. +tests/cases/compiler/immutable.d.ts(89,20): error TS2304: Cannot find name 'Iterable'. +tests/cases/compiler/immutable.d.ts(90,23): error TS2304: Cannot find name 'Iterable'. +tests/cases/compiler/immutable.d.ts(91,23): error TS2304: Cannot find name 'Iterable'. +tests/cases/compiler/immutable.d.ts(92,23): error TS2304: Cannot find name 'Iterable'. +tests/cases/compiler/immutable.d.ts(93,23): error TS2304: Cannot find name 'Iterable'. +tests/cases/compiler/immutable.d.ts(94,22): error TS2304: Cannot find name 'Iterable'. +tests/cases/compiler/immutable.d.ts(95,26): error TS2304: Cannot find name 'Iterable'. +tests/cases/compiler/immutable.d.ts(101,42): error TS2304: Cannot find name 'Iterable'. +tests/cases/compiler/immutable.d.ts(106,58): error TS2304: Cannot find name 'Iterable'. +tests/cases/compiler/immutable.d.ts(113,48): error TS2304: Cannot find name 'Iterable'. +tests/cases/compiler/immutable.d.ts(114,45): error TS2304: Cannot find name 'Iterable'. +tests/cases/compiler/immutable.d.ts(114,54): error TS2304: Cannot find name 'Iterable'. +tests/cases/compiler/immutable.d.ts(120,42): error TS2304: Cannot find name 'Iterable'. +tests/cases/compiler/immutable.d.ts(125,58): error TS2304: Cannot find name 'Iterable'. +tests/cases/compiler/immutable.d.ts(134,33): error TS2304: Cannot find name 'Iterable'. +tests/cases/compiler/immutable.d.ts(134,42): error TS2304: Cannot find name 'Iterable'. +tests/cases/compiler/immutable.d.ts(135,29): error TS2304: Cannot find name 'Iterable'. +tests/cases/compiler/immutable.d.ts(135,38): error TS2304: Cannot find name 'Iterable'. +tests/cases/compiler/immutable.d.ts(139,38): error TS2304: Cannot find name 'Iterable'. +tests/cases/compiler/immutable.d.ts(155,45): error TS2304: Cannot find name 'Iterable'. +tests/cases/compiler/immutable.d.ts(157,62): error TS2304: Cannot find name 'Iterable'. +tests/cases/compiler/immutable.d.ts(169,45): error TS2304: Cannot find name 'Iterable'. +tests/cases/compiler/immutable.d.ts(172,45): error TS2304: Cannot find name 'Iterable'. +tests/cases/compiler/immutable.d.ts(174,62): error TS2304: Cannot find name 'Iterable'. +tests/cases/compiler/immutable.d.ts(188,40): error TS2304: Cannot find name 'Iterable'. +tests/cases/compiler/immutable.d.ts(195,22): error TS2304: Cannot find name 'Iterable'. +tests/cases/compiler/immutable.d.ts(198,19): error TS2304: Cannot find name 'Iterable'. +tests/cases/compiler/immutable.d.ts(205,45): error TS2304: Cannot find name 'Iterable'. +tests/cases/compiler/immutable.d.ts(207,63): error TS2304: Cannot find name 'Iterable'. +tests/cases/compiler/immutable.d.ts(217,30): error TS2304: Cannot find name 'Iterable'. +tests/cases/compiler/immutable.d.ts(218,34): error TS2304: Cannot find name 'Iterable'. +tests/cases/compiler/immutable.d.ts(226,22): error TS2304: Cannot find name 'Iterable'. +tests/cases/compiler/immutable.d.ts(227,22): error TS2304: Cannot find name 'Iterable'. +tests/cases/compiler/immutable.d.ts(234,48): error TS2304: Cannot find name 'Iterable'. +tests/cases/compiler/immutable.d.ts(235,52): error TS2304: Cannot find name 'Iterable'. +tests/cases/compiler/immutable.d.ts(236,109): error TS2304: Cannot find name 'Iterable'. +tests/cases/compiler/immutable.d.ts(237,109): error TS2304: Cannot find name 'Iterable'. +tests/cases/compiler/immutable.d.ts(242,22): error TS2304: Cannot find name 'Iterable'. +tests/cases/compiler/immutable.d.ts(243,25): error TS2304: Cannot find name 'Iterable'. +tests/cases/compiler/immutable.d.ts(244,24): error TS2304: Cannot find name 'Iterable'. +tests/cases/compiler/immutable.d.ts(245,28): error TS2304: Cannot find name 'Iterable'. +tests/cases/compiler/immutable.d.ts(246,25): error TS2304: Cannot find name 'Iterable'. +tests/cases/compiler/immutable.d.ts(247,25): error TS2304: Cannot find name 'Iterable'. +tests/cases/compiler/immutable.d.ts(258,8): error TS2304: Cannot find name 'Symbol'. +tests/cases/compiler/immutable.d.ts(258,28): error TS2304: Cannot find name 'IterableIterator'. +tests/cases/compiler/immutable.d.ts(266,45): error TS2304: Cannot find name 'Iterable'. +tests/cases/compiler/immutable.d.ts(274,44): error TS2304: Cannot find name 'Iterable'. +tests/cases/compiler/immutable.d.ts(279,60): error TS2304: Cannot find name 'Iterable'. +tests/cases/compiler/immutable.d.ts(288,44): error TS2304: Cannot find name 'Iterable'. +tests/cases/compiler/immutable.d.ts(293,47): error TS2304: Cannot find name 'Iterable'. +tests/cases/compiler/immutable.d.ts(295,65): error TS2304: Cannot find name 'Iterable'. +tests/cases/compiler/immutable.d.ts(304,40): error TS2304: Cannot find name 'Iterable'. +tests/cases/compiler/immutable.d.ts(309,47): error TS2304: Cannot find name 'Iterable'. +tests/cases/compiler/immutable.d.ts(311,64): error TS2304: Cannot find name 'Iterable'. +tests/cases/compiler/immutable.d.ts(320,38): error TS2304: Cannot find name 'Iterable'. +tests/cases/compiler/immutable.d.ts(329,58): error TS2304: Cannot find name 'Iterable'. +tests/cases/compiler/immutable.d.ts(339,45): error TS2304: Cannot find name 'Iterable'. +tests/cases/compiler/immutable.d.ts(341,22): error TS2430: Interface 'Keyed' incorrectly extends interface 'Collection'. + Types of property 'toSeq' are incompatible. + Type '() => Keyed' is not assignable to type '() => this'. + Type 'Keyed' is not assignable to type 'this'. +tests/cases/compiler/immutable.d.ts(347,44): error TS2304: Cannot find name 'Iterable'. +tests/cases/compiler/immutable.d.ts(352,60): error TS2304: Cannot find name 'Iterable'. +tests/cases/compiler/immutable.d.ts(355,8): error TS2304: Cannot find name 'Symbol'. +tests/cases/compiler/immutable.d.ts(355,28): error TS2304: Cannot find name 'IterableIterator'. +tests/cases/compiler/immutable.d.ts(358,44): error TS2304: Cannot find name 'Iterable'. +tests/cases/compiler/immutable.d.ts(359,22): error TS2430: Interface 'Indexed' incorrectly extends interface 'Collection'. + Types of property 'toSeq' are incompatible. + Type '() => Indexed' is not assignable to type '() => this'. + Type 'Indexed' is not assignable to type 'this'. +tests/cases/compiler/immutable.d.ts(382,47): error TS2304: Cannot find name 'Iterable'. +tests/cases/compiler/immutable.d.ts(384,65): error TS2304: Cannot find name 'Iterable'. +tests/cases/compiler/immutable.d.ts(387,8): error TS2304: Cannot find name 'Symbol'. +tests/cases/compiler/immutable.d.ts(387,28): error TS2304: Cannot find name 'IterableIterator'. +tests/cases/compiler/immutable.d.ts(390,40): error TS2304: Cannot find name 'Iterable'. +tests/cases/compiler/immutable.d.ts(391,22): error TS2430: Interface 'Set' incorrectly extends interface 'Collection'. + Types of property 'toSeq' are incompatible. + Type '() => Set' is not assignable to type '() => this'. + Type 'Set' is not assignable to type 'this'. +tests/cases/compiler/immutable.d.ts(396,47): error TS2304: Cannot find name 'Iterable'. +tests/cases/compiler/immutable.d.ts(398,64): error TS2304: Cannot find name 'Iterable'. +tests/cases/compiler/immutable.d.ts(401,8): error TS2304: Cannot find name 'Symbol'. +tests/cases/compiler/immutable.d.ts(401,28): error TS2304: Cannot find name 'IterableIterator'. +tests/cases/compiler/immutable.d.ts(405,45): error TS2304: Cannot find name 'Iterable'. +tests/cases/compiler/immutable.d.ts(420,26): error TS2304: Cannot find name 'Iterable'. +tests/cases/compiler/immutable.d.ts(421,26): error TS2304: Cannot find name 'Iterable'. +tests/cases/compiler/immutable.d.ts(442,13): error TS2304: Cannot find name 'IterableIterator'. +tests/cases/compiler/immutable.d.ts(443,15): error TS2304: Cannot find name 'IterableIterator'. +tests/cases/compiler/immutable.d.ts(444,16): error TS2304: Cannot find name 'IterableIterator'. +tests/cases/compiler/immutable.d.ts(476,58): error TS2304: Cannot find name 'Iterable'. +tests/cases/compiler/immutable.d.ts(503,20): error TS2304: Cannot find name 'Iterable'. +tests/cases/compiler/immutable.d.ts(504,22): error TS2304: Cannot find name 'Iterable'. + + +==== tests/cases/compiler/complex.d.ts (0 errors) ==== + interface Ara { t: T } + interface Collection { + map(mapper: (value: V, key: K, iter: this) => M): Collection; + flatMap(mapper: (value: V, key: K, iter: this) => Ara, context?: any): Collection; + // these seem necessary to push it over the top for memory usage + reduce(reducer: (reduction: R, value: V, key: K, iter: this) => R, initialReduction: R, context?: any): R; + reduce(reducer: (reduction: V | R, value: V, key: K, iter: this) => R): R; + toSeq(): Seq; + } + interface Seq extends Collection { + } + interface N1 extends Collection { + map(mapper: (value: T, key: void, iter: this) => M): N1; + flatMap(mapper: (value: T, key: void, iter: this) => Ara, context?: any): N1; + } + interface N2 extends N1 { + map(mapper: (value: T, key: void, iter: this) => M): N2; + flatMap(mapper: (value: T, key: void, iter: this) => Ara, context?: any): N2; + toSeq(): N2; + } +==== tests/cases/compiler/immutable.d.ts (98 errors) ==== + // Test that complex recursive collections can pass the `extends` assignability check without + // running out of memory. This bug was exposed in Typescript 2.4 when more generic signatures + // started being checked. + declare module Immutable { + export function fromJS(jsValue: any, reviver?: (key: string | number, sequence: Collection.Keyed | Collection.Indexed, path?: Array) => any): any; + export function is(first: any, second: any): boolean; + export function hash(value: any): number; + export function isImmutable(maybeImmutable: any): maybeImmutable is Collection; + export function isCollection(maybeCollection: any): maybeCollection is Collection; + export function isKeyed(maybeKeyed: any): maybeKeyed is Collection.Keyed; + export function isIndexed(maybeIndexed: any): maybeIndexed is Collection.Indexed; + export function isAssociative(maybeAssociative: any): maybeAssociative is Collection.Keyed | Collection.Indexed; + export function isOrdered(maybeOrdered: any): boolean; + export function isValueObject(maybeValue: any): maybeValue is ValueObject; + export interface ValueObject { + equals(other: any): boolean; + hashCode(): number; + } + export module List { + function isList(maybeList: any): maybeList is List; + function of(...values: Array): List; + } + export function List(): List; + export function List(): List; + export function List(collection: Iterable): List; + ~~~~~~~~ +!!! error TS2304: Cannot find name 'Iterable'. + export interface List extends Collection.Indexed { + // Persistent changes + set(index: number, value: T): List; + delete(index: number): List; + remove(index: number): List; + insert(index: number, value: T): List; + clear(): List; + push(...values: Array): List; + pop(): List; + unshift(...values: Array): List; + shift(): List; + update(index: number, notSetValue: T, updater: (value: T) => T): this; + update(index: number, updater: (value: T) => T): this; + update(updater: (value: this) => R): R; + merge(...collections: Array | Array>): this; + mergeWith(merger: (oldVal: T, newVal: T, key: number) => T, ...collections: Array | Array>): this; + mergeDeep(...collections: Array | Array>): this; + mergeDeepWith(merger: (oldVal: T, newVal: T, key: number) => T, ...collections: Array | Array>): this; + setSize(size: number): List; + // Deep persistent changes + setIn(keyPath: Iterable, value: any): this; + ~~~~~~~~ +!!! error TS2304: Cannot find name 'Iterable'. + deleteIn(keyPath: Iterable): this; + ~~~~~~~~ +!!! error TS2304: Cannot find name 'Iterable'. + removeIn(keyPath: Iterable): this; + ~~~~~~~~ +!!! error TS2304: Cannot find name 'Iterable'. + updateIn(keyPath: Iterable, notSetValue: any, updater: (value: any) => any): this; + ~~~~~~~~ +!!! error TS2304: Cannot find name 'Iterable'. + updateIn(keyPath: Iterable, updater: (value: any) => any): this; + ~~~~~~~~ +!!! error TS2304: Cannot find name 'Iterable'. + mergeIn(keyPath: Iterable, ...collections: Array): this; + ~~~~~~~~ +!!! error TS2304: Cannot find name 'Iterable'. + mergeDeepIn(keyPath: Iterable, ...collections: Array): this; + ~~~~~~~~ +!!! error TS2304: Cannot find name 'Iterable'. + // Transient changes + withMutations(mutator: (mutable: this) => any): this; + asMutable(): this; + asImmutable(): this; + // Sequence algorithms + concat(...valuesOrCollections: Array | C>): List; + ~~~~~~~~ +!!! error TS2304: Cannot find name 'Iterable'. + map(mapper: (value: T, key: number, iter: this) => M, context?: any): List; + flatMap(mapper: (value: T, key: number, iter: this) => Iterable, context?: any): List; + ~~~~~~~~ +!!! error TS2304: Cannot find name 'Iterable'. + filter(predicate: (value: T, index: number, iter: this) => value is F, context?: any): List; + filter(predicate: (value: T, index: number, iter: this) => any, context?: any): this; + } + export module Map { + function isMap(maybeMap: any): maybeMap is Map; + function of(...keyValues: Array): Map; + } + export function Map(collection: Iterable<[K, V]>): Map; + ~~~~~~~~ +!!! error TS2304: Cannot find name 'Iterable'. + export function Map(collection: Iterable>): Map; + ~~~~~~~~ +!!! error TS2304: Cannot find name 'Iterable'. + ~~~~~~~~ +!!! error TS2304: Cannot find name 'Iterable'. + export function Map(obj: {[key: string]: V}): Map; + export function Map(): Map; + export function Map(): Map; + export interface Map extends Collection.Keyed { + // Persistent changes + set(key: K, value: V): this; + delete(key: K): this; + remove(key: K): this; + deleteAll(keys: Iterable): this; + ~~~~~~~~ +!!! error TS2304: Cannot find name 'Iterable'. + removeAll(keys: Iterable): this; + ~~~~~~~~ +!!! error TS2304: Cannot find name 'Iterable'. + clear(): this; + update(key: K, notSetValue: V, updater: (value: V) => V): this; + update(key: K, updater: (value: V) => V): this; + update(updater: (value: this) => R): R; + merge(...collections: Array | {[key: string]: V}>): this; + mergeWith(merger: (oldVal: V, newVal: V, key: K) => V, ...collections: Array | {[key: string]: V}>): this; + mergeDeep(...collections: Array | {[key: string]: V}>): this; + mergeDeepWith(merger: (oldVal: V, newVal: V, key: K) => V, ...collections: Array | {[key: string]: V}>): this; + // Deep persistent changes + setIn(keyPath: Iterable, value: any): this; + ~~~~~~~~ +!!! error TS2304: Cannot find name 'Iterable'. + deleteIn(keyPath: Iterable): this; + ~~~~~~~~ +!!! error TS2304: Cannot find name 'Iterable'. + removeIn(keyPath: Iterable): this; + ~~~~~~~~ +!!! error TS2304: Cannot find name 'Iterable'. + updateIn(keyPath: Iterable, notSetValue: any, updater: (value: any) => any): this; + ~~~~~~~~ +!!! error TS2304: Cannot find name 'Iterable'. + updateIn(keyPath: Iterable, updater: (value: any) => any): this; + ~~~~~~~~ +!!! error TS2304: Cannot find name 'Iterable'. + mergeIn(keyPath: Iterable, ...collections: Array): this; + ~~~~~~~~ +!!! error TS2304: Cannot find name 'Iterable'. + mergeDeepIn(keyPath: Iterable, ...collections: Array): this; + ~~~~~~~~ +!!! error TS2304: Cannot find name 'Iterable'. + // Transient changes + withMutations(mutator: (mutable: this) => any): this; + asMutable(): this; + asImmutable(): this; + // Sequence algorithms + concat(...collections: Array>): Map; + ~~~~~~~~ +!!! error TS2304: Cannot find name 'Iterable'. + concat(...collections: Array<{[key: string]: C}>): Map; + map(mapper: (value: V, key: K, iter: this) => M, context?: any): Map; + mapKeys(mapper: (key: K, value: V, iter: this) => M, context?: any): Map; + mapEntries(mapper: (entry: [K, V], index: number, iter: this) => [KM, VM], context?: any): Map; + flatMap(mapper: (value: V, key: K, iter: this) => Iterable, context?: any): Map; + ~~~~~~~~ +!!! error TS2304: Cannot find name 'Iterable'. + filter(predicate: (value: V, key: K, iter: this) => value is F, context?: any): Map; + filter(predicate: (value: V, key: K, iter: this) => any, context?: any): this; + } + export module OrderedMap { + function isOrderedMap(maybeOrderedMap: any): maybeOrderedMap is OrderedMap; + } + export function OrderedMap(collection: Iterable<[K, V]>): OrderedMap; + ~~~~~~~~ +!!! error TS2304: Cannot find name 'Iterable'. + export function OrderedMap(collection: Iterable>): OrderedMap; + ~~~~~~~~ +!!! error TS2304: Cannot find name 'Iterable'. + ~~~~~~~~ +!!! error TS2304: Cannot find name 'Iterable'. + export function OrderedMap(obj: {[key: string]: V}): OrderedMap; + export function OrderedMap(): OrderedMap; + export function OrderedMap(): OrderedMap; + export interface OrderedMap extends Map { + // Sequence algorithms + concat(...collections: Array>): OrderedMap; + ~~~~~~~~ +!!! error TS2304: Cannot find name 'Iterable'. + concat(...collections: Array<{[key: string]: C}>): OrderedMap; + map(mapper: (value: V, key: K, iter: this) => M, context?: any): OrderedMap; + mapKeys(mapper: (key: K, value: V, iter: this) => M, context?: any): OrderedMap; + mapEntries(mapper: (entry: [K, V], index: number, iter: this) => [KM, VM], context?: any): OrderedMap; + flatMap(mapper: (value: V, key: K, iter: this) => Iterable, context?: any): OrderedMap; + ~~~~~~~~ +!!! error TS2304: Cannot find name 'Iterable'. + filter(predicate: (value: V, key: K, iter: this) => value is F, context?: any): OrderedMap; + filter(predicate: (value: V, key: K, iter: this) => any, context?: any): this; + } + export module Set { + function isSet(maybeSet: any): maybeSet is Set; + function of(...values: Array): Set; + function fromKeys(iter: Collection): Set; + function fromKeys(obj: {[key: string]: any}): Set; + function intersect(sets: Iterable>): Set; + ~~~~~~~~ +!!! error TS2304: Cannot find name 'Iterable'. + ~~~~~~~~ +!!! error TS2304: Cannot find name 'Iterable'. + function union(sets: Iterable>): Set; + ~~~~~~~~ +!!! error TS2304: Cannot find name 'Iterable'. + ~~~~~~~~ +!!! error TS2304: Cannot find name 'Iterable'. + } + export function Set(): Set; + export function Set(): Set; + export function Set(collection: Iterable): Set; + ~~~~~~~~ +!!! error TS2304: Cannot find name 'Iterable'. + export interface Set extends Collection.Set { + // Persistent changes + add(value: T): this; + delete(value: T): this; + remove(value: T): this; + clear(): this; + union(...collections: Array | Array>): this; + merge(...collections: Array | Array>): this; + intersect(...collections: Array | Array>): this; + subtract(...collections: Array | Array>): this; + // Transient changes + withMutations(mutator: (mutable: this) => any): this; + asMutable(): this; + asImmutable(): this; + // Sequence algorithms + concat(...valuesOrCollections: Array | C>): Set; + ~~~~~~~~ +!!! error TS2304: Cannot find name 'Iterable'. + map(mapper: (value: T, key: never, iter: this) => M, context?: any): Set; + flatMap(mapper: (value: T, key: never, iter: this) => Iterable, context?: any): Set; + ~~~~~~~~ +!!! error TS2304: Cannot find name 'Iterable'. + filter(predicate: (value: T, key: never, iter: this) => value is F, context?: any): Set; + filter(predicate: (value: T, key: never, iter: this) => any, context?: any): this; + } + export module OrderedSet { + function isOrderedSet(maybeOrderedSet: any): boolean; + function of(...values: Array): OrderedSet; + function fromKeys(iter: Collection): OrderedSet; + function fromKeys(obj: {[key: string]: any}): OrderedSet; + } + export function OrderedSet(): OrderedSet; + export function OrderedSet(): OrderedSet; + export function OrderedSet(collection: Iterable): OrderedSet; + ~~~~~~~~ +!!! error TS2304: Cannot find name 'Iterable'. + export interface OrderedSet extends Set { + // Sequence algorithms + concat(...valuesOrCollections: Array | C>): OrderedSet; + ~~~~~~~~ +!!! error TS2304: Cannot find name 'Iterable'. + map(mapper: (value: T, key: never, iter: this) => M, context?: any): OrderedSet; + flatMap(mapper: (value: T, key: never, iter: this) => Iterable, context?: any): OrderedSet; + ~~~~~~~~ +!!! error TS2304: Cannot find name 'Iterable'. + filter(predicate: (value: T, key: never, iter: this) => value is F, context?: any): OrderedSet; + filter(predicate: (value: T, key: never, iter: this) => any, context?: any): this; + zip(...collections: Array>): OrderedSet; + zipWith(zipper: (value: T, otherValue: U) => Z, otherCollection: Collection): OrderedSet; + zipWith(zipper: (value: T, otherValue: U, thirdValue: V) => Z, otherCollection: Collection, thirdCollection: Collection): OrderedSet; + zipWith(zipper: (...any: Array) => Z, ...collections: Array>): OrderedSet; + } + export module Stack { + function isStack(maybeStack: any): maybeStack is Stack; + function of(...values: Array): Stack; + } + export function Stack(): Stack; + export function Stack(): Stack; + export function Stack(collection: Iterable): Stack; + ~~~~~~~~ +!!! error TS2304: Cannot find name 'Iterable'. + export interface Stack extends Collection.Indexed { + // Reading values + peek(): T | undefined; + // Persistent changes + clear(): Stack; + unshift(...values: Array): Stack; + unshiftAll(iter: Iterable): Stack; + ~~~~~~~~ +!!! error TS2304: Cannot find name 'Iterable'. + shift(): Stack; + push(...values: Array): Stack; + pushAll(iter: Iterable): Stack; + ~~~~~~~~ +!!! error TS2304: Cannot find name 'Iterable'. + pop(): Stack; + // Transient changes + withMutations(mutator: (mutable: this) => any): this; + asMutable(): this; + asImmutable(): this; + // Sequence algorithms + concat(...valuesOrCollections: Array | C>): Stack; + ~~~~~~~~ +!!! error TS2304: Cannot find name 'Iterable'. + map(mapper: (value: T, key: number, iter: this) => M, context?: any): Stack; + flatMap(mapper: (value: T, key: number, iter: this) => Iterable, context?: any): Stack; + ~~~~~~~~ +!!! error TS2304: Cannot find name 'Iterable'. + filter(predicate: (value: T, index: number, iter: this) => value is F, context?: any): Set; + filter(predicate: (value: T, index: number, iter: this) => any, context?: any): this; + } + export function Range(start?: number, end?: number, step?: number): Seq.Indexed; + export function Repeat(value: T, times?: number): Seq.Indexed; + export module Record { + export function isRecord(maybeRecord: any): maybeRecord is Record.Instance; + export function getDescriptiveName(record: Instance): string; + export interface Class { + (values?: Partial | Iterable<[string, any]>): Instance & Readonly; + ~~~~~~~~ +!!! error TS2304: Cannot find name 'Iterable'. + new (values?: Partial | Iterable<[string, any]>): Instance & Readonly; + ~~~~~~~~ +!!! error TS2304: Cannot find name 'Iterable'. + } + export interface Instance { + readonly size: number; + // Reading values + has(key: string): boolean; + get(key: K): T[K]; + // Reading deep values + hasIn(keyPath: Iterable): boolean; + ~~~~~~~~ +!!! error TS2304: Cannot find name 'Iterable'. + getIn(keyPath: Iterable): any; + ~~~~~~~~ +!!! error TS2304: Cannot find name 'Iterable'. + // Value equality + equals(other: any): boolean; + hashCode(): number; + // Persistent changes + set(key: K, value: T[K]): this; + update(key: K, updater: (value: T[K]) => T[K]): this; + merge(...collections: Array | Iterable<[string, any]>>): this; + ~~~~~~~~ +!!! error TS2304: Cannot find name 'Iterable'. + mergeDeep(...collections: Array | Iterable<[string, any]>>): this; + ~~~~~~~~ +!!! error TS2304: Cannot find name 'Iterable'. + mergeWith(merger: (oldVal: any, newVal: any, key: keyof T) => any, ...collections: Array | Iterable<[string, any]>>): this; + ~~~~~~~~ +!!! error TS2304: Cannot find name 'Iterable'. + mergeDeepWith(merger: (oldVal: any, newVal: any, key: any) => any, ...collections: Array | Iterable<[string, any]>>): this; + ~~~~~~~~ +!!! error TS2304: Cannot find name 'Iterable'. + delete(key: K): this; + remove(key: K): this; + clear(): this; + // Deep persistent changes + setIn(keyPath: Iterable, value: any): this; + ~~~~~~~~ +!!! error TS2304: Cannot find name 'Iterable'. + updateIn(keyPath: Iterable, updater: (value: any) => any): this; + ~~~~~~~~ +!!! error TS2304: Cannot find name 'Iterable'. + mergeIn(keyPath: Iterable, ...collections: Array): this; + ~~~~~~~~ +!!! error TS2304: Cannot find name 'Iterable'. + mergeDeepIn(keyPath: Iterable, ...collections: Array): this; + ~~~~~~~~ +!!! error TS2304: Cannot find name 'Iterable'. + deleteIn(keyPath: Iterable): this; + ~~~~~~~~ +!!! error TS2304: Cannot find name 'Iterable'. + removeIn(keyPath: Iterable): this; + ~~~~~~~~ +!!! error TS2304: Cannot find name 'Iterable'. + // Conversion to JavaScript types + toJS(): { [K in keyof T]: any }; + toJSON(): T; + toObject(): T; + // Transient changes + withMutations(mutator: (mutable: this) => any): this; + asMutable(): this; + asImmutable(): this; + // Sequence algorithms + toSeq(): Seq.Keyed; + [Symbol.iterator](): IterableIterator<[keyof T, T[keyof T]]>; + ~~~~~~ +!!! error TS2304: Cannot find name 'Symbol'. + ~~~~~~~~~~~~~~~~ +!!! error TS2304: Cannot find name 'IterableIterator'. + } + } + export function Record(defaultValues: T, name?: string): Record.Class; + export module Seq { + function isSeq(maybeSeq: any): maybeSeq is Seq.Indexed | Seq.Keyed; + function of(...values: Array): Seq.Indexed; + export module Keyed {} + export function Keyed(collection: Iterable<[K, V]>): Seq.Keyed; + ~~~~~~~~ +!!! error TS2304: Cannot find name 'Iterable'. + export function Keyed(obj: {[key: string]: V}): Seq.Keyed; + export function Keyed(): Seq.Keyed; + export function Keyed(): Seq.Keyed; + export interface Keyed extends Seq, Collection.Keyed { + toJS(): Object; + toJSON(): { [key: string]: V }; + toSeq(): this; + concat(...collections: Array>): Seq.Keyed; + ~~~~~~~~ +!!! error TS2304: Cannot find name 'Iterable'. + concat(...collections: Array<{[key: string]: C}>): Seq.Keyed; + map(mapper: (value: V, key: K, iter: this) => M, context?: any): Seq.Keyed; + mapKeys(mapper: (key: K, value: V, iter: this) => M, context?: any): Seq.Keyed; + mapEntries(mapper: (entry: [K, V], index: number, iter: this) => [KM, VM], context?: any): Seq.Keyed; + flatMap(mapper: (value: V, key: K, iter: this) => Iterable, context?: any): Seq.Keyed; + ~~~~~~~~ +!!! error TS2304: Cannot find name 'Iterable'. + filter(predicate: (value: V, key: K, iter: this) => value is F, context?: any): Seq.Keyed; + filter(predicate: (value: V, key: K, iter: this) => any, context?: any): this; + } + module Indexed { + function of(...values: Array): Seq.Indexed; + } + export function Indexed(): Seq.Indexed; + export function Indexed(): Seq.Indexed; + export function Indexed(collection: Iterable): Seq.Indexed; + ~~~~~~~~ +!!! error TS2304: Cannot find name 'Iterable'. + export interface Indexed extends Seq, Collection.Indexed { + toJS(): Array; + toJSON(): Array; + toSeq(): this; + concat(...valuesOrCollections: Array | C>): Seq.Indexed; + ~~~~~~~~ +!!! error TS2304: Cannot find name 'Iterable'. + map(mapper: (value: T, key: number, iter: this) => M, context?: any): Seq.Indexed; + flatMap(mapper: (value: T, key: number, iter: this) => Iterable, context?: any): Seq.Indexed; + ~~~~~~~~ +!!! error TS2304: Cannot find name 'Iterable'. + filter(predicate: (value: T, index: number, iter: this) => value is F, context?: any): Seq.Indexed; + filter(predicate: (value: T, index: number, iter: this) => any, context?: any): this; + } + export module Set { + function of(...values: Array): Seq.Set; + } + export function Set(): Seq.Set; + export function Set(): Seq.Set; + export function Set(collection: Iterable): Seq.Set; + ~~~~~~~~ +!!! error TS2304: Cannot find name 'Iterable'. + export interface Set extends Seq, Collection.Set { + toJS(): Array; + toJSON(): Array; + toSeq(): this; + concat(...valuesOrCollections: Array | C>): Seq.Set; + ~~~~~~~~ +!!! error TS2304: Cannot find name 'Iterable'. + map(mapper: (value: T, key: never, iter: this) => M, context?: any): Seq.Set; + flatMap(mapper: (value: T, key: never, iter: this) => Iterable, context?: any): Seq.Set; + ~~~~~~~~ +!!! error TS2304: Cannot find name 'Iterable'. + filter(predicate: (value: T, key: never, iter: this) => value is F, context?: any): Seq.Set; + filter(predicate: (value: T, key: never, iter: this) => any, context?: any): this; + } + } + export function Seq>(seq: S): S; + export function Seq(collection: Collection.Keyed): Seq.Keyed; + export function Seq(collection: Collection.Indexed): Seq.Indexed; + export function Seq(collection: Collection.Set): Seq.Set; + export function Seq(collection: Iterable): Seq.Indexed; + ~~~~~~~~ +!!! error TS2304: Cannot find name 'Iterable'. + export function Seq(obj: {[key: string]: V}): Seq.Keyed; + export function Seq(): Seq; + export interface Seq extends Collection { + readonly size: number | undefined; + // Force evaluation + cacheResult(): this; + // Sequence algorithms + map(mapper: (value: V, key: K, iter: this) => M, context?: any): Seq; + flatMap(mapper: (value: V, key: K, iter: this) => Iterable, context?: any): Seq; + ~~~~~~~~ +!!! error TS2304: Cannot find name 'Iterable'. + filter(predicate: (value: V, key: K, iter: this) => value is F, context?: any): Seq; + filter(predicate: (value: V, key: K, iter: this) => any, context?: any): this; + } + export module Collection { + function isKeyed(maybeKeyed: any): maybeKeyed is Collection.Keyed; + function isIndexed(maybeIndexed: any): maybeIndexed is Collection.Indexed; + function isAssociative(maybeAssociative: any): maybeAssociative is Collection.Keyed | Collection.Indexed; + function isOrdered(maybeOrdered: any): boolean; + export module Keyed {} + export function Keyed(collection: Iterable<[K, V]>): Collection.Keyed; + ~~~~~~~~ +!!! error TS2304: Cannot find name 'Iterable'. + export function Keyed(obj: {[key: string]: V}): Collection.Keyed; + export interface Keyed extends Collection { + ~~~~~ +!!! error TS2430: Interface 'Keyed' incorrectly extends interface 'Collection'. +!!! error TS2430: Types of property 'toSeq' are incompatible. +!!! error TS2430: Type '() => Keyed' is not assignable to type '() => this'. +!!! error TS2430: Type 'Keyed' is not assignable to type 'this'. + toJS(): Object; + toJSON(): { [key: string]: V }; + toSeq(): Seq.Keyed; + // Sequence functions + flip(): this; + concat(...collections: Array>): Collection.Keyed; + ~~~~~~~~ +!!! error TS2304: Cannot find name 'Iterable'. + concat(...collections: Array<{[key: string]: C}>): Collection.Keyed; + map(mapper: (value: V, key: K, iter: this) => M, context?: any): Collection.Keyed; + mapKeys(mapper: (key: K, value: V, iter: this) => M, context?: any): Collection.Keyed; + mapEntries(mapper: (entry: [K, V], index: number, iter: this) => [KM, VM], context?: any): Collection.Keyed; + flatMap(mapper: (value: V, key: K, iter: this) => Iterable, context?: any): Collection.Keyed; + ~~~~~~~~ +!!! error TS2304: Cannot find name 'Iterable'. + filter(predicate: (value: V, key: K, iter: this) => value is F, context?: any): Collection.Keyed; + filter(predicate: (value: V, key: K, iter: this) => any, context?: any): this; + [Symbol.iterator](): IterableIterator<[K, V]>; + ~~~~~~ +!!! error TS2304: Cannot find name 'Symbol'. + ~~~~~~~~~~~~~~~~ +!!! error TS2304: Cannot find name 'IterableIterator'. + } + export module Indexed {} + export function Indexed(collection: Iterable): Collection.Indexed; + ~~~~~~~~ +!!! error TS2304: Cannot find name 'Iterable'. + export interface Indexed extends Collection { + ~~~~~~~ +!!! error TS2430: Interface 'Indexed' incorrectly extends interface 'Collection'. +!!! error TS2430: Types of property 'toSeq' are incompatible. +!!! error TS2430: Type '() => Indexed' is not assignable to type '() => this'. +!!! error TS2430: Type 'Indexed' is not assignable to type 'this'. + toJS(): Array; + toJSON(): Array; + // Reading values + get(index: number, notSetValue: NSV): T | NSV; + get(index: number): T | undefined; + // Conversion to Seq + toSeq(): Seq.Indexed; + fromEntrySeq(): Seq.Keyed; + // Combination + interpose(separator: T): this; + interleave(...collections: Array>): this; + splice(index: number, removeNum: number, ...values: Array): this; + zip(...collections: Array>): Collection.Indexed; + zipWith(zipper: (value: T, otherValue: U) => Z, otherCollection: Collection): Collection.Indexed; + zipWith(zipper: (value: T, otherValue: U, thirdValue: V) => Z, otherCollection: Collection, thirdCollection: Collection): Collection.Indexed; + zipWith(zipper: (...any: Array) => Z, ...collections: Array>): Collection.Indexed; + // Search for value + indexOf(searchValue: T): number; + lastIndexOf(searchValue: T): number; + findIndex(predicate: (value: T, index: number, iter: this) => boolean, context?: any): number; + findLastIndex(predicate: (value: T, index: number, iter: this) => boolean, context?: any): number; + // Sequence algorithms + concat(...valuesOrCollections: Array | C>): Collection.Indexed; + ~~~~~~~~ +!!! error TS2304: Cannot find name 'Iterable'. + map(mapper: (value: T, key: number, iter: this) => M, context?: any): Collection.Indexed; + flatMap(mapper: (value: T, key: number, iter: this) => Iterable, context?: any): Collection.Indexed; + ~~~~~~~~ +!!! error TS2304: Cannot find name 'Iterable'. + filter(predicate: (value: T, index: number, iter: this) => value is F, context?: any): Collection.Indexed; + filter(predicate: (value: T, index: number, iter: this) => any, context?: any): this; + [Symbol.iterator](): IterableIterator; + ~~~~~~ +!!! error TS2304: Cannot find name 'Symbol'. + ~~~~~~~~~~~~~~~~ +!!! error TS2304: Cannot find name 'IterableIterator'. + } + export module Set {} + export function Set(collection: Iterable): Collection.Set; + ~~~~~~~~ +!!! error TS2304: Cannot find name 'Iterable'. + export interface Set extends Collection { + ~~~ +!!! error TS2430: Interface 'Set' incorrectly extends interface 'Collection'. +!!! error TS2430: Types of property 'toSeq' are incompatible. +!!! error TS2430: Type '() => Set' is not assignable to type '() => this'. +!!! error TS2430: Type 'Set' is not assignable to type 'this'. + toJS(): Array; + toJSON(): Array; + toSeq(): Seq.Set; + // Sequence algorithms + concat(...valuesOrCollections: Array | C>): Collection.Set; + ~~~~~~~~ +!!! error TS2304: Cannot find name 'Iterable'. + map(mapper: (value: T, key: never, iter: this) => M, context?: any): Collection.Set; + flatMap(mapper: (value: T, key: never, iter: this) => Iterable, context?: any): Collection.Set; + ~~~~~~~~ +!!! error TS2304: Cannot find name 'Iterable'. + filter(predicate: (value: T, key: never, iter: this) => value is F, context?: any): Collection.Set; + filter(predicate: (value: T, key: never, iter: this) => any, context?: any): this; + [Symbol.iterator](): IterableIterator; + ~~~~~~ +!!! error TS2304: Cannot find name 'Symbol'. + ~~~~~~~~~~~~~~~~ +!!! error TS2304: Cannot find name 'IterableIterator'. + } + } + export function Collection>(collection: I): I; + export function Collection(collection: Iterable): Collection.Indexed; + ~~~~~~~~ +!!! error TS2304: Cannot find name 'Iterable'. + export function Collection(obj: {[key: string]: V}): Collection.Keyed; + export interface Collection extends ValueObject { + // Value equality + equals(other: any): boolean; + hashCode(): number; + // Reading values + get(key: K, notSetValue: NSV): V | NSV; + get(key: K): V | undefined; + has(key: K): boolean; + includes(value: V): boolean; + contains(value: V): boolean; + first(): V | undefined; + last(): V | undefined; + // Reading deep values + getIn(searchKeyPath: Iterable, notSetValue?: any): any; + ~~~~~~~~ +!!! error TS2304: Cannot find name 'Iterable'. + hasIn(searchKeyPath: Iterable): boolean; + ~~~~~~~~ +!!! error TS2304: Cannot find name 'Iterable'. + // Persistent changes + update(updater: (value: this) => R): R; + // Conversion to JavaScript types + toJS(): Array | { [key: string]: any }; + toJSON(): Array | { [key: string]: V }; + toArray(): Array; + toObject(): { [key: string]: V }; + // Conversion to Collections + toMap(): Map; + toOrderedMap(): OrderedMap; + toSet(): Set; + toOrderedSet(): OrderedSet; + toList(): List; + toStack(): Stack; + // Conversion to Seq + toSeq(): this; + toKeyedSeq(): Seq.Keyed; + toIndexedSeq(): Seq.Indexed; + toSetSeq(): Seq.Set; + // Iterators + keys(): IterableIterator; + ~~~~~~~~~~~~~~~~ +!!! error TS2304: Cannot find name 'IterableIterator'. + values(): IterableIterator; + ~~~~~~~~~~~~~~~~ +!!! error TS2304: Cannot find name 'IterableIterator'. + entries(): IterableIterator<[K, V]>; + ~~~~~~~~~~~~~~~~ +!!! error TS2304: Cannot find name 'IterableIterator'. + // Collections (Seq) + keySeq(): Seq.Indexed; + valueSeq(): Seq.Indexed; + entrySeq(): Seq.Indexed<[K, V]>; + // Sequence algorithms + map(mapper: (value: V, key: K, iter: this) => M, context?: any): Collection; + filter(predicate: (value: V, key: K, iter: this) => value is F, context?: any): Collection; + filter(predicate: (value: V, key: K, iter: this) => any, context?: any): this; + filterNot(predicate: (value: V, key: K, iter: this) => boolean, context?: any): this; + reverse(): this; + sort(comparator?: (valueA: V, valueB: V) => number): this; + sortBy(comparatorValueMapper: (value: V, key: K, iter: this) => C, comparator?: (valueA: C, valueB: C) => number): this; + groupBy(grouper: (value: V, key: K, iter: this) => G, context?: any): /*Map*/Seq.Keyed>; + // Side effects + forEach(sideEffect: (value: V, key: K, iter: this) => any, context?: any): number; + // Creating subsets + slice(begin?: number, end?: number): this; + rest(): this; + butLast(): this; + skip(amount: number): this; + skipLast(amount: number): this; + skipWhile(predicate: (value: V, key: K, iter: this) => boolean, context?: any): this; + skipUntil(predicate: (value: V, key: K, iter: this) => boolean, context?: any): this; + take(amount: number): this; + takeLast(amount: number): this; + takeWhile(predicate: (value: V, key: K, iter: this) => boolean, context?: any): this; + takeUntil(predicate: (value: V, key: K, iter: this) => boolean, context?: any): this; + // Combination + concat(...valuesOrCollections: Array): Collection; + flatten(depth?: number): Collection; + flatten(shallow?: boolean): Collection; + flatMap(mapper: (value: V, key: K, iter: this) => Iterable, context?: any): Collection; + ~~~~~~~~ +!!! error TS2304: Cannot find name 'Iterable'. + // Reducing a value + reduce(reducer: (reduction: R, value: V, key: K, iter: this) => R, initialReduction: R, context?: any): R; + reduce(reducer: (reduction: V | R, value: V, key: K, iter: this) => R): R; + reduceRight(reducer: (reduction: R, value: V, key: K, iter: this) => R, initialReduction: R, context?: any): R; + reduceRight(reducer: (reduction: V | R, value: V, key: K, iter: this) => R): R; + every(predicate: (value: V, key: K, iter: this) => boolean, context?: any): boolean; + some(predicate: (value: V, key: K, iter: this) => boolean, context?: any): boolean; + join(separator?: string): string; + isEmpty(): boolean; + count(): number; + count(predicate: (value: V, key: K, iter: this) => boolean, context?: any): number; + countBy(grouper: (value: V, key: K, iter: this) => G, context?: any): Map; + // Search for value + find(predicate: (value: V, key: K, iter: this) => boolean, context?: any, notSetValue?: V): V | undefined; + findLast(predicate: (value: V, key: K, iter: this) => boolean, context?: any, notSetValue?: V): V | undefined; + findEntry(predicate: (value: V, key: K, iter: this) => boolean, context?: any, notSetValue?: V): [K, V] | undefined; + findLastEntry(predicate: (value: V, key: K, iter: this) => boolean, context?: any, notSetValue?: V): [K, V] | undefined; + findKey(predicate: (value: V, key: K, iter: this) => boolean, context?: any): K | undefined; + findLastKey(predicate: (value: V, key: K, iter: this) => boolean, context?: any): K | undefined; + keyOf(searchValue: V): K | undefined; + lastKeyOf(searchValue: V): K | undefined; + max(comparator?: (valueA: V, valueB: V) => number): V | undefined; + maxBy(comparatorValueMapper: (value: V, key: K, iter: this) => C, comparator?: (valueA: C, valueB: C) => number): V | undefined; + min(comparator?: (valueA: V, valueB: V) => number): V | undefined; + minBy(comparatorValueMapper: (value: V, key: K, iter: this) => C, comparator?: (valueA: C, valueB: C) => number): V | undefined; + // Comparison + isSubset(iter: Iterable): boolean; + ~~~~~~~~ +!!! error TS2304: Cannot find name 'Iterable'. + isSuperset(iter: Iterable): boolean; + ~~~~~~~~ +!!! error TS2304: Cannot find name 'Iterable'. + readonly size: number; + } + } + declare module "immutable" { + export = Immutable + } + \ No newline at end of file diff --git a/tests/cases/compiler/complexRecursiveCollections.ts b/tests/cases/compiler/complexRecursiveCollections.ts new file mode 100644 index 0000000000000..a79b429f20435 --- /dev/null +++ b/tests/cases/compiler/complexRecursiveCollections.ts @@ -0,0 +1,532 @@ +// @Filename: complex.d.ts +interface Ara { t: T } +interface Collection { + map(mapper: (value: V, key: K, iter: this) => M): Collection; + flatMap(mapper: (value: V, key: K, iter: this) => Ara, context?: any): Collection; + // these seem necessary to push it over the top for memory usage + reduce(reducer: (reduction: R, value: V, key: K, iter: this) => R, initialReduction: R, context?: any): R; + reduce(reducer: (reduction: V | R, value: V, key: K, iter: this) => R): R; + toSeq(): Seq; +} +interface Seq extends Collection { +} +interface N1 extends Collection { + map(mapper: (value: T, key: void, iter: this) => M): N1; + flatMap(mapper: (value: T, key: void, iter: this) => Ara, context?: any): N1; +} +interface N2 extends N1 { + map(mapper: (value: T, key: void, iter: this) => M): N2; + flatMap(mapper: (value: T, key: void, iter: this) => Ara, context?: any): N2; + toSeq(): N2; +} +// @Filename: immutable.d.ts +// Test that complex recursive collections can pass the `extends` assignability check without +// running out of memory. This bug was exposed in Typescript 2.4 when more generic signatures +// started being checked. +declare module Immutable { + export function fromJS(jsValue: any, reviver?: (key: string | number, sequence: Collection.Keyed | Collection.Indexed, path?: Array) => any): any; + export function is(first: any, second: any): boolean; + export function hash(value: any): number; + export function isImmutable(maybeImmutable: any): maybeImmutable is Collection; + export function isCollection(maybeCollection: any): maybeCollection is Collection; + export function isKeyed(maybeKeyed: any): maybeKeyed is Collection.Keyed; + export function isIndexed(maybeIndexed: any): maybeIndexed is Collection.Indexed; + export function isAssociative(maybeAssociative: any): maybeAssociative is Collection.Keyed | Collection.Indexed; + export function isOrdered(maybeOrdered: any): boolean; + export function isValueObject(maybeValue: any): maybeValue is ValueObject; + export interface ValueObject { + equals(other: any): boolean; + hashCode(): number; + } + export module List { + function isList(maybeList: any): maybeList is List; + function of(...values: Array): List; + } + export function List(): List; + export function List(): List; + export function List(collection: Iterable): List; + export interface List extends Collection.Indexed { + // Persistent changes + set(index: number, value: T): List; + delete(index: number): List; + remove(index: number): List; + insert(index: number, value: T): List; + clear(): List; + push(...values: Array): List; + pop(): List; + unshift(...values: Array): List; + shift(): List; + update(index: number, notSetValue: T, updater: (value: T) => T): this; + update(index: number, updater: (value: T) => T): this; + update(updater: (value: this) => R): R; + merge(...collections: Array | Array>): this; + mergeWith(merger: (oldVal: T, newVal: T, key: number) => T, ...collections: Array | Array>): this; + mergeDeep(...collections: Array | Array>): this; + mergeDeepWith(merger: (oldVal: T, newVal: T, key: number) => T, ...collections: Array | Array>): this; + setSize(size: number): List; + // Deep persistent changes + setIn(keyPath: Iterable, value: any): this; + deleteIn(keyPath: Iterable): this; + removeIn(keyPath: Iterable): this; + updateIn(keyPath: Iterable, notSetValue: any, updater: (value: any) => any): this; + updateIn(keyPath: Iterable, updater: (value: any) => any): this; + mergeIn(keyPath: Iterable, ...collections: Array): this; + mergeDeepIn(keyPath: Iterable, ...collections: Array): this; + // Transient changes + withMutations(mutator: (mutable: this) => any): this; + asMutable(): this; + asImmutable(): this; + // Sequence algorithms + concat(...valuesOrCollections: Array | C>): List; + map(mapper: (value: T, key: number, iter: this) => M, context?: any): List; + flatMap(mapper: (value: T, key: number, iter: this) => Iterable, context?: any): List; + filter(predicate: (value: T, index: number, iter: this) => value is F, context?: any): List; + filter(predicate: (value: T, index: number, iter: this) => any, context?: any): this; + } + export module Map { + function isMap(maybeMap: any): maybeMap is Map; + function of(...keyValues: Array): Map; + } + export function Map(collection: Iterable<[K, V]>): Map; + export function Map(collection: Iterable>): Map; + export function Map(obj: {[key: string]: V}): Map; + export function Map(): Map; + export function Map(): Map; + export interface Map extends Collection.Keyed { + // Persistent changes + set(key: K, value: V): this; + delete(key: K): this; + remove(key: K): this; + deleteAll(keys: Iterable): this; + removeAll(keys: Iterable): this; + clear(): this; + update(key: K, notSetValue: V, updater: (value: V) => V): this; + update(key: K, updater: (value: V) => V): this; + update(updater: (value: this) => R): R; + merge(...collections: Array | {[key: string]: V}>): this; + mergeWith(merger: (oldVal: V, newVal: V, key: K) => V, ...collections: Array | {[key: string]: V}>): this; + mergeDeep(...collections: Array | {[key: string]: V}>): this; + mergeDeepWith(merger: (oldVal: V, newVal: V, key: K) => V, ...collections: Array | {[key: string]: V}>): this; + // Deep persistent changes + setIn(keyPath: Iterable, value: any): this; + deleteIn(keyPath: Iterable): this; + removeIn(keyPath: Iterable): this; + updateIn(keyPath: Iterable, notSetValue: any, updater: (value: any) => any): this; + updateIn(keyPath: Iterable, updater: (value: any) => any): this; + mergeIn(keyPath: Iterable, ...collections: Array): this; + mergeDeepIn(keyPath: Iterable, ...collections: Array): this; + // Transient changes + withMutations(mutator: (mutable: this) => any): this; + asMutable(): this; + asImmutable(): this; + // Sequence algorithms + concat(...collections: Array>): Map; + concat(...collections: Array<{[key: string]: C}>): Map; + map(mapper: (value: V, key: K, iter: this) => M, context?: any): Map; + mapKeys(mapper: (key: K, value: V, iter: this) => M, context?: any): Map; + mapEntries(mapper: (entry: [K, V], index: number, iter: this) => [KM, VM], context?: any): Map; + flatMap(mapper: (value: V, key: K, iter: this) => Iterable, context?: any): Map; + filter(predicate: (value: V, key: K, iter: this) => value is F, context?: any): Map; + filter(predicate: (value: V, key: K, iter: this) => any, context?: any): this; + } + export module OrderedMap { + function isOrderedMap(maybeOrderedMap: any): maybeOrderedMap is OrderedMap; + } + export function OrderedMap(collection: Iterable<[K, V]>): OrderedMap; + export function OrderedMap(collection: Iterable>): OrderedMap; + export function OrderedMap(obj: {[key: string]: V}): OrderedMap; + export function OrderedMap(): OrderedMap; + export function OrderedMap(): OrderedMap; + export interface OrderedMap extends Map { + // Sequence algorithms + concat(...collections: Array>): OrderedMap; + concat(...collections: Array<{[key: string]: C}>): OrderedMap; + map(mapper: (value: V, key: K, iter: this) => M, context?: any): OrderedMap; + mapKeys(mapper: (key: K, value: V, iter: this) => M, context?: any): OrderedMap; + mapEntries(mapper: (entry: [K, V], index: number, iter: this) => [KM, VM], context?: any): OrderedMap; + flatMap(mapper: (value: V, key: K, iter: this) => Iterable, context?: any): OrderedMap; + filter(predicate: (value: V, key: K, iter: this) => value is F, context?: any): OrderedMap; + filter(predicate: (value: V, key: K, iter: this) => any, context?: any): this; + } + export module Set { + function isSet(maybeSet: any): maybeSet is Set; + function of(...values: Array): Set; + function fromKeys(iter: Collection): Set; + function fromKeys(obj: {[key: string]: any}): Set; + function intersect(sets: Iterable>): Set; + function union(sets: Iterable>): Set; + } + export function Set(): Set; + export function Set(): Set; + export function Set(collection: Iterable): Set; + export interface Set extends Collection.Set { + // Persistent changes + add(value: T): this; + delete(value: T): this; + remove(value: T): this; + clear(): this; + union(...collections: Array | Array>): this; + merge(...collections: Array | Array>): this; + intersect(...collections: Array | Array>): this; + subtract(...collections: Array | Array>): this; + // Transient changes + withMutations(mutator: (mutable: this) => any): this; + asMutable(): this; + asImmutable(): this; + // Sequence algorithms + concat(...valuesOrCollections: Array | C>): Set; + map(mapper: (value: T, key: never, iter: this) => M, context?: any): Set; + flatMap(mapper: (value: T, key: never, iter: this) => Iterable, context?: any): Set; + filter(predicate: (value: T, key: never, iter: this) => value is F, context?: any): Set; + filter(predicate: (value: T, key: never, iter: this) => any, context?: any): this; + } + export module OrderedSet { + function isOrderedSet(maybeOrderedSet: any): boolean; + function of(...values: Array): OrderedSet; + function fromKeys(iter: Collection): OrderedSet; + function fromKeys(obj: {[key: string]: any}): OrderedSet; + } + export function OrderedSet(): OrderedSet; + export function OrderedSet(): OrderedSet; + export function OrderedSet(collection: Iterable): OrderedSet; + export interface OrderedSet extends Set { + // Sequence algorithms + concat(...valuesOrCollections: Array | C>): OrderedSet; + map(mapper: (value: T, key: never, iter: this) => M, context?: any): OrderedSet; + flatMap(mapper: (value: T, key: never, iter: this) => Iterable, context?: any): OrderedSet; + filter(predicate: (value: T, key: never, iter: this) => value is F, context?: any): OrderedSet; + filter(predicate: (value: T, key: never, iter: this) => any, context?: any): this; + zip(...collections: Array>): OrderedSet; + zipWith(zipper: (value: T, otherValue: U) => Z, otherCollection: Collection): OrderedSet; + zipWith(zipper: (value: T, otherValue: U, thirdValue: V) => Z, otherCollection: Collection, thirdCollection: Collection): OrderedSet; + zipWith(zipper: (...any: Array) => Z, ...collections: Array>): OrderedSet; + } + export module Stack { + function isStack(maybeStack: any): maybeStack is Stack; + function of(...values: Array): Stack; + } + export function Stack(): Stack; + export function Stack(): Stack; + export function Stack(collection: Iterable): Stack; + export interface Stack extends Collection.Indexed { + // Reading values + peek(): T | undefined; + // Persistent changes + clear(): Stack; + unshift(...values: Array): Stack; + unshiftAll(iter: Iterable): Stack; + shift(): Stack; + push(...values: Array): Stack; + pushAll(iter: Iterable): Stack; + pop(): Stack; + // Transient changes + withMutations(mutator: (mutable: this) => any): this; + asMutable(): this; + asImmutable(): this; + // Sequence algorithms + concat(...valuesOrCollections: Array | C>): Stack; + map(mapper: (value: T, key: number, iter: this) => M, context?: any): Stack; + flatMap(mapper: (value: T, key: number, iter: this) => Iterable, context?: any): Stack; + filter(predicate: (value: T, index: number, iter: this) => value is F, context?: any): Set; + filter(predicate: (value: T, index: number, iter: this) => any, context?: any): this; + } + export function Range(start?: number, end?: number, step?: number): Seq.Indexed; + export function Repeat(value: T, times?: number): Seq.Indexed; + export module Record { + export function isRecord(maybeRecord: any): maybeRecord is Record.Instance; + export function getDescriptiveName(record: Instance): string; + export interface Class { + (values?: Partial | Iterable<[string, any]>): Instance & Readonly; + new (values?: Partial | Iterable<[string, any]>): Instance & Readonly; + } + export interface Instance { + readonly size: number; + // Reading values + has(key: string): boolean; + get(key: K): T[K]; + // Reading deep values + hasIn(keyPath: Iterable): boolean; + getIn(keyPath: Iterable): any; + // Value equality + equals(other: any): boolean; + hashCode(): number; + // Persistent changes + set(key: K, value: T[K]): this; + update(key: K, updater: (value: T[K]) => T[K]): this; + merge(...collections: Array | Iterable<[string, any]>>): this; + mergeDeep(...collections: Array | Iterable<[string, any]>>): this; + mergeWith(merger: (oldVal: any, newVal: any, key: keyof T) => any, ...collections: Array | Iterable<[string, any]>>): this; + mergeDeepWith(merger: (oldVal: any, newVal: any, key: any) => any, ...collections: Array | Iterable<[string, any]>>): this; + delete(key: K): this; + remove(key: K): this; + clear(): this; + // Deep persistent changes + setIn(keyPath: Iterable, value: any): this; + updateIn(keyPath: Iterable, updater: (value: any) => any): this; + mergeIn(keyPath: Iterable, ...collections: Array): this; + mergeDeepIn(keyPath: Iterable, ...collections: Array): this; + deleteIn(keyPath: Iterable): this; + removeIn(keyPath: Iterable): this; + // Conversion to JavaScript types + toJS(): { [K in keyof T]: any }; + toJSON(): T; + toObject(): T; + // Transient changes + withMutations(mutator: (mutable: this) => any): this; + asMutable(): this; + asImmutable(): this; + // Sequence algorithms + toSeq(): Seq.Keyed; + [Symbol.iterator](): IterableIterator<[keyof T, T[keyof T]]>; + } + } + export function Record(defaultValues: T, name?: string): Record.Class; + export module Seq { + function isSeq(maybeSeq: any): maybeSeq is Seq.Indexed | Seq.Keyed; + function of(...values: Array): Seq.Indexed; + export module Keyed {} + export function Keyed(collection: Iterable<[K, V]>): Seq.Keyed; + export function Keyed(obj: {[key: string]: V}): Seq.Keyed; + export function Keyed(): Seq.Keyed; + export function Keyed(): Seq.Keyed; + export interface Keyed extends Seq, Collection.Keyed { + toJS(): Object; + toJSON(): { [key: string]: V }; + toSeq(): this; + concat(...collections: Array>): Seq.Keyed; + concat(...collections: Array<{[key: string]: C}>): Seq.Keyed; + map(mapper: (value: V, key: K, iter: this) => M, context?: any): Seq.Keyed; + mapKeys(mapper: (key: K, value: V, iter: this) => M, context?: any): Seq.Keyed; + mapEntries(mapper: (entry: [K, V], index: number, iter: this) => [KM, VM], context?: any): Seq.Keyed; + flatMap(mapper: (value: V, key: K, iter: this) => Iterable, context?: any): Seq.Keyed; + filter(predicate: (value: V, key: K, iter: this) => value is F, context?: any): Seq.Keyed; + filter(predicate: (value: V, key: K, iter: this) => any, context?: any): this; + } + module Indexed { + function of(...values: Array): Seq.Indexed; + } + export function Indexed(): Seq.Indexed; + export function Indexed(): Seq.Indexed; + export function Indexed(collection: Iterable): Seq.Indexed; + export interface Indexed extends Seq, Collection.Indexed { + toJS(): Array; + toJSON(): Array; + toSeq(): this; + concat(...valuesOrCollections: Array | C>): Seq.Indexed; + map(mapper: (value: T, key: number, iter: this) => M, context?: any): Seq.Indexed; + flatMap(mapper: (value: T, key: number, iter: this) => Iterable, context?: any): Seq.Indexed; + filter(predicate: (value: T, index: number, iter: this) => value is F, context?: any): Seq.Indexed; + filter(predicate: (value: T, index: number, iter: this) => any, context?: any): this; + } + export module Set { + function of(...values: Array): Seq.Set; + } + export function Set(): Seq.Set; + export function Set(): Seq.Set; + export function Set(collection: Iterable): Seq.Set; + export interface Set extends Seq, Collection.Set { + toJS(): Array; + toJSON(): Array; + toSeq(): this; + concat(...valuesOrCollections: Array | C>): Seq.Set; + map(mapper: (value: T, key: never, iter: this) => M, context?: any): Seq.Set; + flatMap(mapper: (value: T, key: never, iter: this) => Iterable, context?: any): Seq.Set; + filter(predicate: (value: T, key: never, iter: this) => value is F, context?: any): Seq.Set; + filter(predicate: (value: T, key: never, iter: this) => any, context?: any): this; + } + } + export function Seq>(seq: S): S; + export function Seq(collection: Collection.Keyed): Seq.Keyed; + export function Seq(collection: Collection.Indexed): Seq.Indexed; + export function Seq(collection: Collection.Set): Seq.Set; + export function Seq(collection: Iterable): Seq.Indexed; + export function Seq(obj: {[key: string]: V}): Seq.Keyed; + export function Seq(): Seq; + export interface Seq extends Collection { + readonly size: number | undefined; + // Force evaluation + cacheResult(): this; + // Sequence algorithms + map(mapper: (value: V, key: K, iter: this) => M, context?: any): Seq; + flatMap(mapper: (value: V, key: K, iter: this) => Iterable, context?: any): Seq; + filter(predicate: (value: V, key: K, iter: this) => value is F, context?: any): Seq; + filter(predicate: (value: V, key: K, iter: this) => any, context?: any): this; + } + export module Collection { + function isKeyed(maybeKeyed: any): maybeKeyed is Collection.Keyed; + function isIndexed(maybeIndexed: any): maybeIndexed is Collection.Indexed; + function isAssociative(maybeAssociative: any): maybeAssociative is Collection.Keyed | Collection.Indexed; + function isOrdered(maybeOrdered: any): boolean; + export module Keyed {} + export function Keyed(collection: Iterable<[K, V]>): Collection.Keyed; + export function Keyed(obj: {[key: string]: V}): Collection.Keyed; + export interface Keyed extends Collection { + toJS(): Object; + toJSON(): { [key: string]: V }; + toSeq(): Seq.Keyed; + // Sequence functions + flip(): this; + concat(...collections: Array>): Collection.Keyed; + concat(...collections: Array<{[key: string]: C}>): Collection.Keyed; + map(mapper: (value: V, key: K, iter: this) => M, context?: any): Collection.Keyed; + mapKeys(mapper: (key: K, value: V, iter: this) => M, context?: any): Collection.Keyed; + mapEntries(mapper: (entry: [K, V], index: number, iter: this) => [KM, VM], context?: any): Collection.Keyed; + flatMap(mapper: (value: V, key: K, iter: this) => Iterable, context?: any): Collection.Keyed; + filter(predicate: (value: V, key: K, iter: this) => value is F, context?: any): Collection.Keyed; + filter(predicate: (value: V, key: K, iter: this) => any, context?: any): this; + [Symbol.iterator](): IterableIterator<[K, V]>; + } + export module Indexed {} + export function Indexed(collection: Iterable): Collection.Indexed; + export interface Indexed extends Collection { + toJS(): Array; + toJSON(): Array; + // Reading values + get(index: number, notSetValue: NSV): T | NSV; + get(index: number): T | undefined; + // Conversion to Seq + toSeq(): Seq.Indexed; + fromEntrySeq(): Seq.Keyed; + // Combination + interpose(separator: T): this; + interleave(...collections: Array>): this; + splice(index: number, removeNum: number, ...values: Array): this; + zip(...collections: Array>): Collection.Indexed; + zipWith(zipper: (value: T, otherValue: U) => Z, otherCollection: Collection): Collection.Indexed; + zipWith(zipper: (value: T, otherValue: U, thirdValue: V) => Z, otherCollection: Collection, thirdCollection: Collection): Collection.Indexed; + zipWith(zipper: (...any: Array) => Z, ...collections: Array>): Collection.Indexed; + // Search for value + indexOf(searchValue: T): number; + lastIndexOf(searchValue: T): number; + findIndex(predicate: (value: T, index: number, iter: this) => boolean, context?: any): number; + findLastIndex(predicate: (value: T, index: number, iter: this) => boolean, context?: any): number; + // Sequence algorithms + concat(...valuesOrCollections: Array | C>): Collection.Indexed; + map(mapper: (value: T, key: number, iter: this) => M, context?: any): Collection.Indexed; + flatMap(mapper: (value: T, key: number, iter: this) => Iterable, context?: any): Collection.Indexed; + filter(predicate: (value: T, index: number, iter: this) => value is F, context?: any): Collection.Indexed; + filter(predicate: (value: T, index: number, iter: this) => any, context?: any): this; + [Symbol.iterator](): IterableIterator; + } + export module Set {} + export function Set(collection: Iterable): Collection.Set; + export interface Set extends Collection { + toJS(): Array; + toJSON(): Array; + toSeq(): Seq.Set; + // Sequence algorithms + concat(...valuesOrCollections: Array | C>): Collection.Set; + map(mapper: (value: T, key: never, iter: this) => M, context?: any): Collection.Set; + flatMap(mapper: (value: T, key: never, iter: this) => Iterable, context?: any): Collection.Set; + filter(predicate: (value: T, key: never, iter: this) => value is F, context?: any): Collection.Set; + filter(predicate: (value: T, key: never, iter: this) => any, context?: any): this; + [Symbol.iterator](): IterableIterator; + } + } + export function Collection>(collection: I): I; + export function Collection(collection: Iterable): Collection.Indexed; + export function Collection(obj: {[key: string]: V}): Collection.Keyed; + export interface Collection extends ValueObject { + // Value equality + equals(other: any): boolean; + hashCode(): number; + // Reading values + get(key: K, notSetValue: NSV): V | NSV; + get(key: K): V | undefined; + has(key: K): boolean; + includes(value: V): boolean; + contains(value: V): boolean; + first(): V | undefined; + last(): V | undefined; + // Reading deep values + getIn(searchKeyPath: Iterable, notSetValue?: any): any; + hasIn(searchKeyPath: Iterable): boolean; + // Persistent changes + update(updater: (value: this) => R): R; + // Conversion to JavaScript types + toJS(): Array | { [key: string]: any }; + toJSON(): Array | { [key: string]: V }; + toArray(): Array; + toObject(): { [key: string]: V }; + // Conversion to Collections + toMap(): Map; + toOrderedMap(): OrderedMap; + toSet(): Set; + toOrderedSet(): OrderedSet; + toList(): List; + toStack(): Stack; + // Conversion to Seq + toSeq(): this; + toKeyedSeq(): Seq.Keyed; + toIndexedSeq(): Seq.Indexed; + toSetSeq(): Seq.Set; + // Iterators + keys(): IterableIterator; + values(): IterableIterator; + entries(): IterableIterator<[K, V]>; + // Collections (Seq) + keySeq(): Seq.Indexed; + valueSeq(): Seq.Indexed; + entrySeq(): Seq.Indexed<[K, V]>; + // Sequence algorithms + map(mapper: (value: V, key: K, iter: this) => M, context?: any): Collection; + filter(predicate: (value: V, key: K, iter: this) => value is F, context?: any): Collection; + filter(predicate: (value: V, key: K, iter: this) => any, context?: any): this; + filterNot(predicate: (value: V, key: K, iter: this) => boolean, context?: any): this; + reverse(): this; + sort(comparator?: (valueA: V, valueB: V) => number): this; + sortBy(comparatorValueMapper: (value: V, key: K, iter: this) => C, comparator?: (valueA: C, valueB: C) => number): this; + groupBy(grouper: (value: V, key: K, iter: this) => G, context?: any): /*Map*/Seq.Keyed>; + // Side effects + forEach(sideEffect: (value: V, key: K, iter: this) => any, context?: any): number; + // Creating subsets + slice(begin?: number, end?: number): this; + rest(): this; + butLast(): this; + skip(amount: number): this; + skipLast(amount: number): this; + skipWhile(predicate: (value: V, key: K, iter: this) => boolean, context?: any): this; + skipUntil(predicate: (value: V, key: K, iter: this) => boolean, context?: any): this; + take(amount: number): this; + takeLast(amount: number): this; + takeWhile(predicate: (value: V, key: K, iter: this) => boolean, context?: any): this; + takeUntil(predicate: (value: V, key: K, iter: this) => boolean, context?: any): this; + // Combination + concat(...valuesOrCollections: Array): Collection; + flatten(depth?: number): Collection; + flatten(shallow?: boolean): Collection; + flatMap(mapper: (value: V, key: K, iter: this) => Iterable, context?: any): Collection; + // Reducing a value + reduce(reducer: (reduction: R, value: V, key: K, iter: this) => R, initialReduction: R, context?: any): R; + reduce(reducer: (reduction: V | R, value: V, key: K, iter: this) => R): R; + reduceRight(reducer: (reduction: R, value: V, key: K, iter: this) => R, initialReduction: R, context?: any): R; + reduceRight(reducer: (reduction: V | R, value: V, key: K, iter: this) => R): R; + every(predicate: (value: V, key: K, iter: this) => boolean, context?: any): boolean; + some(predicate: (value: V, key: K, iter: this) => boolean, context?: any): boolean; + join(separator?: string): string; + isEmpty(): boolean; + count(): number; + count(predicate: (value: V, key: K, iter: this) => boolean, context?: any): number; + countBy(grouper: (value: V, key: K, iter: this) => G, context?: any): Map; + // Search for value + find(predicate: (value: V, key: K, iter: this) => boolean, context?: any, notSetValue?: V): V | undefined; + findLast(predicate: (value: V, key: K, iter: this) => boolean, context?: any, notSetValue?: V): V | undefined; + findEntry(predicate: (value: V, key: K, iter: this) => boolean, context?: any, notSetValue?: V): [K, V] | undefined; + findLastEntry(predicate: (value: V, key: K, iter: this) => boolean, context?: any, notSetValue?: V): [K, V] | undefined; + findKey(predicate: (value: V, key: K, iter: this) => boolean, context?: any): K | undefined; + findLastKey(predicate: (value: V, key: K, iter: this) => boolean, context?: any): K | undefined; + keyOf(searchValue: V): K | undefined; + lastKeyOf(searchValue: V): K | undefined; + max(comparator?: (valueA: V, valueB: V) => number): V | undefined; + maxBy(comparatorValueMapper: (value: V, key: K, iter: this) => C, comparator?: (valueA: C, valueB: C) => number): V | undefined; + min(comparator?: (valueA: V, valueB: V) => number): V | undefined; + minBy(comparatorValueMapper: (value: V, key: K, iter: this) => C, comparator?: (valueA: C, valueB: C) => number): V | undefined; + // Comparison + isSubset(iter: Iterable): boolean; + isSuperset(iter: Iterable): boolean; + readonly size: number; + } +} +declare module "immutable" { + export = Immutable +} From 7a9491384c24f02757d23751da16bf647abd8b49 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Wed, 23 Aug 2017 11:49:24 -0700 Subject: [PATCH 4/5] Update baselines --- .../reference/typeParameterAssignmentCompat1.errors.txt | 6 ------ 1 file changed, 6 deletions(-) diff --git a/tests/baselines/reference/typeParameterAssignmentCompat1.errors.txt b/tests/baselines/reference/typeParameterAssignmentCompat1.errors.txt index 9665ef017c02e..2ca4299c7f8d6 100644 --- a/tests/baselines/reference/typeParameterAssignmentCompat1.errors.txt +++ b/tests/baselines/reference/typeParameterAssignmentCompat1.errors.txt @@ -1,11 +1,8 @@ tests/cases/compiler/typeParameterAssignmentCompat1.ts(8,5): error TS2322: Type 'Foo' is not assignable to type 'Foo'. Type 'U' is not assignable to type 'T'. tests/cases/compiler/typeParameterAssignmentCompat1.ts(9,5): error TS2322: Type 'Foo' is not assignable to type 'Foo'. - Type 'T' is not assignable to type 'U'. tests/cases/compiler/typeParameterAssignmentCompat1.ts(16,9): error TS2322: Type 'Foo' is not assignable to type 'Foo'. - Type 'U' is not assignable to type 'T'. tests/cases/compiler/typeParameterAssignmentCompat1.ts(17,9): error TS2322: Type 'Foo' is not assignable to type 'Foo'. - Type 'T' is not assignable to type 'U'. ==== tests/cases/compiler/typeParameterAssignmentCompat1.ts (4 errors) ==== @@ -23,7 +20,6 @@ tests/cases/compiler/typeParameterAssignmentCompat1.ts(17,9): error TS2322: Type return x; ~~~~~~~~~ !!! error TS2322: Type 'Foo' is not assignable to type 'Foo'. -!!! error TS2322: Type 'T' is not assignable to type 'U'. } class C { @@ -33,10 +29,8 @@ tests/cases/compiler/typeParameterAssignmentCompat1.ts(17,9): error TS2322: Type x = y; // should be an error ~ !!! error TS2322: Type 'Foo' is not assignable to type 'Foo'. -!!! error TS2322: Type 'U' is not assignable to type 'T'. return x; ~~~~~~~~~ !!! error TS2322: Type 'Foo' is not assignable to type 'Foo'. -!!! error TS2322: Type 'T' is not assignable to type 'U'. } } \ No newline at end of file From f30931cddd606a34143b10049255185b8810a30c Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Wed, 23 Aug 2017 11:57:06 -0700 Subject: [PATCH 5/5] Comment getTypeReferenceId and getRelationKey --- src/compiler/checker.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 3accf1637386e..4124fefbe95bd 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -9779,6 +9779,10 @@ namespace ts { return getObjectFlags(type) & ObjectFlags.Reference && some((type).typeArguments, isUnconstrainedTypeParameter); } + /** + * getTypeReferenceId(A) returns "111=0-12=1" + * where A.id=111 and number.id=12 + */ function getTypeReferenceId(type: TypeReference, typeParameters: Type[]) { let result = "" + type.target.id; for (const t of type.typeArguments) { @@ -9797,6 +9801,10 @@ namespace ts { return result; } + /** + * To improve caching, the relation key for two generic types uses the target's id plus ids of the type parameters. + * For other cases, the types ids are used. + */ function getRelationKey(source: Type, target: Type, relation: Map) { if (relation === identityRelation && source.id > target.id) { const temp = source;