Open History to see the last commit
1import { describe, expectTypeOf, it } from 'vitest'
2import { D2, join } from '../../src/index.js'
3import type { IStreamBuilder, JoinType, KeyValue } from '../../src/index.js'
4
5// `join(other, type)` is the only join operator. Its result type does not
6// depend on the join type: every pair side is nullable, so an inner join's
7// caller narrows or casts it. The removed `innerJoin` returned `[V1, V2]`.
8type Left = { left: string }
9type Right = { right: number }
10
11describe(`join result types`, () => {
12 it.each([`inner`, `left`, `right`, `full`, `anti`] as const)(
13 `types a %s join's pair sides as nullable`,
14 (type: JoinType) => {
15 const graph = new D2()
16 const left = graph.newInput<KeyValue<number, Left>>()
17 const right = graph.newInput<KeyValue<number, Right>>()
18 const joined = left.pipe(join(right, type))
19 expectTypeOf(joined).toEqualTypeOf<
20 IStreamBuilder<KeyValue<number, [Left | null, Right | null]>>
21 >()
22 },
23 )
24
25 it(`defaults to an inner join with the same result type`, () => {
26 const graph = new D2()
27 const left = graph.newInput<KeyValue<number, Left>>()
28 const right = graph.newInput<KeyValue<number, Right>>()
29 expectTypeOf(left.pipe(join(right))).toEqualTypeOf<
30 IStreamBuilder<KeyValue<number, [Left | null, Right | null]>>
31 >()
32 })
33})