Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🚧 [Help Wanted] types for endpoint(options) #50

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

gr2m
Copy link
Contributor

@gr2m gr2m commented Apr 19, 2020

This pull requests attempts to introduce type validations for endpoint(options). It looks for the options.method and options.url and compares them to known routes. If there is a match, it enforces the required options for that route and returns a better typed result.

The problem is that TypeScript throws an error for EndpointsByUrlAndMethod[O["url"]][O["method"]]["request"]

Expression produces a union type that is too complex to represent

I don't know if that is resolvable at all. I might have hit a limit of what TypeScript is capable of doing.

The reason I'd like to make this possible is that we would no longer require defining custom type definitions for rest endpoint methods as we do in https://raw.githubusercontent.com/octokit/plugin-rest-endpoint-methods.js/53e3403d39e35b25ac3b5ae872895ab4277067cd/src/generated/types.ts, because all typings would be set correctly by doing sth like this

import { Octokit } from `@octokit/core`
const octokit = new Octokit({ auth: 'secret123' })
const createIssue = request.defaults({ method: 'POST', url: '/repos/:owner/:repo/issues' })

If anyone is up for a challenge, it's all yours :)

@gr2m gr2m added Status: Up for grabs Issues that are ready to be worked on by anyone typescript Relevant to TypeScript users only labels Apr 19, 2020
@gr2m gr2m changed the title o 🚧 [Help Wanted] types for endpoint(options) Apr 19, 2020
@gr2m
Copy link
Contributor Author

gr2m commented Apr 19, 2020

I worked around the error in cf2782a, but some functionality is missing (see test.ts). Plus, probably more importantly, the TypeScript Intellisense in VS Code got unusable slow

@gr2m gr2m added the Type: Feature New feature or request label May 5, 2020
@gr2m gr2m added this to Features in JS May 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Up for grabs Issues that are ready to be worked on by anyone Type: Feature New feature or request typescript Relevant to TypeScript users only
Projects
No open projects
JS
  
Features
Development

Successfully merging this pull request may close these issues.

None yet

1 participant