Skip to content

question: how can i create and return a generic function in TypeScript? #9949

Closed
@zpdDG4gta8XKpMCd

Description

@zpdDG4gta8XKpMCd
function flip<a, b, c>(fn: (one: a, two: b) => c): (one: b, two: a) => c {
    return function flipped(one: b, two: a): c {
        return fn(two, one);
    };
}
function of2<a, b>(one: a, two: b): [a, b] {
    return [one, two];
}
const flipped = flip(of2); // expected: <a, b>(one: b, two: a) => [a, b], actual: (one: {}, two: {}) => [{}, {}]

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already createdFixedA PR has been merged for this issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions