Skip to content

Commit 1f9b922

Browse files
types(Collection): union types on intersect and difference (#7196)
1 parent b7856e7 commit 1f9b922

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

Diff for: packages/collection/src/index.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -629,8 +629,8 @@ export class Collection<K, V> extends Map<K, V> {
629629
*
630630
* @param other The other Collection to filter against
631631
*/
632-
public intersect(other: Collection<K, V>) {
633-
const coll = new this.constructor[Symbol.species]<K, V>();
632+
public intersect<T>(other: Collection<K, T>): Collection<K, T> {
633+
const coll = new this.constructor[Symbol.species]<K, T>();
634634
for (const [k, v] of other) {
635635
if (this.has(k)) coll.set(k, v);
636636
}
@@ -642,8 +642,8 @@ export class Collection<K, V> extends Map<K, V> {
642642
*
643643
* @param other The other Collection to filter against
644644
*/
645-
public difference(other: Collection<K, V>) {
646-
const coll = new this.constructor[Symbol.species]<K, V>();
645+
public difference<T>(other: Collection<K, T>): Collection<K, V | T> {
646+
const coll = new this.constructor[Symbol.species]<K, V | T>();
647647
for (const [k, v] of other) {
648648
if (!this.has(k)) coll.set(k, v);
649649
}

0 commit comments

Comments
 (0)