types(Collection): union types on intersect and difference (#7196)

This commit is contained in:
Suneet Tipirneni
2022-01-07 18:47:55 -05:00
committed by GitHub
parent b7856e7809
commit 1f9b9225f2

View File

@@ -629,8 +629,8 @@ export class Collection<K, V> extends Map<K, V> {
*
* @param other The other Collection to filter against
*/
public intersect(other: Collection<K, V>) {
const coll = new this.constructor[Symbol.species]<K, V>();
public intersect<T>(other: Collection<K, T>): Collection<K, T> {
const coll = new this.constructor[Symbol.species]<K, T>();
for (const [k, v] of other) {
if (this.has(k)) coll.set(k, v);
}
@@ -642,8 +642,8 @@ export class Collection<K, V> extends Map<K, V> {
*
* @param other The other Collection to filter against
*/
public difference(other: Collection<K, V>) {
const coll = new this.constructor[Symbol.species]<K, V>();
public difference<T>(other: Collection<K, T>): Collection<K, V | T> {
const coll = new this.constructor[Symbol.species]<K, V | T>();
for (const [k, v] of other) {
if (!this.has(k)) coll.set(k, v);
}