Inferring with infer
infer captures a type inside a conditional type.
Example
type Item<T> = T extends (infer U)[] ? U : T;
const n: Item<number[]> = 5;
console.log(n);Result
5
Exercise
Capture a type.
T extends ( U)[] ? U : T
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.