Create a typed StreamChunk by event type. Narrows the return to the * matching variant via `Extract`.
( type: T, fields?: Record<string, unknown>, )
| 23 | /** Create a typed StreamChunk by event type. Narrows the return to the |
| 24 | * matching variant via `Extract`. */ |
| 25 | function chunk<T extends StreamChunk['type']>( |
| 26 | type: T, |
| 27 | fields?: Record<string, unknown>, |
| 28 | ): Extract<StreamChunk, { type: T }> { |
| 29 | return { type, timestamp: Date.now(), ...fields } as Extract< |
| 30 | StreamChunk, |
| 31 | { type: T } |
| 32 | > |
| 33 | } |
| 34 | |
| 35 | /** Create an async iterable from a list of chunks. */ |
| 36 | async function* streamOf( |
no test coverage detected