Open pikatchu opened 1 week ago
Summarizing offline discussion: It would be possible to give joinCollections
the type
export function joinCollections<
K extends Json,
V1 extends JsonObject,
V2 extends JsonObject,
>(
col1: EagerCollection<K, V1>,
col2: EagerCollection<K, V2>,
allowMultipleValuesOnBothSides: boolean = false,
): EagerCollection<K, V1 & V2>
and propagate JsonObject
down, eliminating the checks that each value is an object.
BUT, since typescript unsoundly treats method parameters as bivariant, calling joinCollections
e.g. from createGraph
where inputCollections: Record<string, EagerCollection<Json, Json>>
will not detect mistakes where general Json
values are provided where JsonObject
s are required. So this PR's dynamic checks on each value are still needed. Thanks for nothing typescript.
This diff implements the 'join' operation of two collections. It is assumed that:
If both those conditions are met, given a key, if the first collection defines an object of type V1 and the second collection defines an object V2 for the same key, the resulting collection will associate {...V1, ...V2} for that key. No value is associated if either side is missing.