Complete the code to infer the type of the first element in a tuple.
type First<T extends any[]> = T extends [[1], ...any[]] ? [1] : never;
infer....any[] to match the rest of the tuple.The infer keyword is used to declare a type variable U that captures the first element's type in the tuple T.
Complete the code to infer the return type of a function type.
type ReturnType<T> = T extends (...args: any[]) => [1] ? [1] : never;
void instead of infer.The infer R captures the return type of the function T.
Fix the error in the code to infer the element type of an array type.
type ElementType<T> = T extends Array<[1]> ? [1] : never;
infer.any which loses type information.infer E is needed to capture the element type inside the array type T.
Fill both blanks to infer the argument types of a function type as a tuple.
type Args<T> = T extends (...args: [1]) => any ? [2] : never;
any[] instead of infer.infer A captures the tuple of argument types from the function type T.
Fill all three blanks to infer the resolved type from a Promise type.
type UnwrapPromise<T> = T extends Promise<[1]> ? [1] : T extends Promise<[2]> ? [3] : T;
infer to capture the inner type.The first infer U captures the type inside the Promise. Then U is used to return the resolved type.
