Dev Helpers
← Back

Infer a dictionary value

Infer a dictionary value using TypeScript.

Open this example in the interactive library

Source code

type ElementOf<T> = T extends readonly (infer U)[] ? U : never;
console.log(
  (() => {
    type Val<T> = T extends Record<string, infer V> ? V : never;
    const n: Val<Record<string, number>> = 3;
    return n;
  })(),
);

Sample output

3