It is possible to generalize liftN to any number of arguments:
export function liftN<T extends NewtypeRepr<N>[], N extends Newtype<any, any> = never>(f: (...args: T) => NewtypeRepr<N>): (...args: { [K in keyof T]: N; }) => N {
return f as unknown as (...args: { [K in keyof T]: N; }) => N;
}
Unfortunately, this requires users to explicitly pass in the type of their parameter list as an argument, even though type inference is good enough to figure it out. We'd like T to be inferred, but N to have to be explicit.
It is possible to generalize
liftNto any number of arguments:Unfortunately, this requires users to explicitly pass in the type of their parameter list as an argument, even though type inference is good enough to figure it out. We'd like
Tto be inferred, butNto have to be explicit.