Skip to content

Latest commit

 

History

History
36 lines (27 loc) · 789 Bytes

File metadata and controls

36 lines (27 loc) · 789 Bytes

Home > types-kit > IterableValue

IterableValue type

Get the value type of an Iterable / AsyncIterable.

Signature:

export type IterableValue<T> = T extends Iterable<infer U>
  ? U
  : T extends AsyncIterable<infer U>
  ? U
  : never

Example

function* IterableValueFoo() {
      yield 1
      yield 2
   }
   // Expect: 1 | 2
   type FooType = IterableValue<ReturnType<typeof IterableValueFoo>>
   async function* IterableValueBar() {
      yield 3
      yield 4
   }
   // Expect: 3 | 4
   type BarType = IterableValue<ReturnType<typeof IterableValueBar>>