Skip to content

Conversation

@ptomulik
Copy link
Contributor

Redefines the MapFunction generic interface, such that it can be reused in a definition of all the overloads in PaginateInerface/ComposePaginateInterface. This shall also prevent further bugs such as #259.

@ptomulik
Copy link
Contributor Author

ptomulik commented Mar 11, 2021

By the way, I've seen this comment and I came across the following idea.

interface Overloads {
    0: (t1: number) => number;
    1: (t1: number, t2: number) => number;
}

interface Generate<Prepend extends []|[string]> {
    (...args: [...Prepend, ...Parameters<Overloads[0]>]): ReturnType<Overloads[0]>;
    (...args: [...Prepend, ...Parameters<Overloads[1]>]): ReturnType<Overloads[1]>;
}

type Normal = Generate<[]>; // Generate Overloads
type Prepended = Generate<[string]>; // Generate Overloads with leading argument of type string

const normal: Normal = (t1: number, t2?: number) => {
    return t1 + (t2 === undefined ? 0 : t2);
}

const prepended: Prepended = (s: string, t1: number, t2?: number) => {
    console.log(s);
    return t1 + (t2 === undefined ? 0 : t2);
}

console.log(normal(1));
console.log(normal(1, 2));
console.log(prepended("one", 1));
console.log(prepended("two plus three", 2, 3));

The problem is, however, that argument names are lost, together with docstrings.

@gr2m
Copy link
Contributor

gr2m commented Mar 11, 2021

By the way, I've seen this comment and I came across the following idea.

this is great, could you please move it in a separate issue for further discussion?

Copy link
Contributor

@gr2m gr2m left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very nice, thank you!

@gr2m gr2m added bug typescript Relevant to TypeScript users only labels Mar 11, 2021
@gr2m gr2m changed the title refactor MapFunction to be more reusable fix(typescript): improve internal MapFunction type Mar 11, 2021
@gr2m gr2m merged commit a779629 into octokit:master Mar 11, 2021
@github-actions
Copy link
Contributor

🎉 This PR is included in version 2.13.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

typescript Relevant to TypeScript users only

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants