Skip to content

Generalize liftN #2

@kanwren

Description

@kanwren

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions