Loading...
function pick<T extends string>(options: T[], fallback: T) {
return fallback;
}
pick(['sm', 'md'], 'xl');function pick<T extends string>(options: T[], fallback: NoInfer<T>) {
return fallback;
}
pick(['sm', 'md'], 'xl'); // errorNoInfer stops fallback from widening T, so 'xl' is rejected because it is not in the options list.
NoInfer wraps only the parameters that should be checked against T, not the ones that define it.U extends T added only to block inference.No, NoInfer<T> checks the same as T. It only stops that position from being used to infer T, and like all types it is erased at runtime.
With an extra type parameter such as <T, U extends T>, where U takes the argument. NoInfer replaces that trick.