Skip to content
This repository has been archived by the owner on Jan 8, 2022. It is now read-only.

types: union value types on intersect and difference #56

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down