The infer keyword compliments conditional types and cannot be used outside an extends clause. infer is used within conditional types to declare a type variable within our constraint to capture types dynamically within the extends clause of a conditional type.

type NullableString = string | null | undefined

type NonNullable<T> = T extends null | undefined ? never : T // Built-in type, FYI

type CondUnionType = NonNullable<NullableString> // evalutes to `string`


type Extract<T, U> = T extends U ? T : never
type Exclude<T, U> = T extends U ? never : T

// figures out the return type of a function
type ReturnType<T> = T extends (...args: any[]) => infer R ? R : any;

type Flatten<T> = T extends Array<infer U> ? Flatten<U> : T;

type NestedArray = number\[][\][];
type Flat = Flatten<NestedArray>;  // This will be 'number'

https://blog.logrocket.com/understanding-infer-typescript/