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

Define a type for items in "SearchIssuesAndPullRequestsResponseData" type. #120

Closed
sarvaje opened this issue Jun 26, 2020 · 6 comments · Fixed by #197
Closed

Define a type for items in "SearchIssuesAndPullRequestsResponseData" type. #120

sarvaje opened this issue Jun 26, 2020 · 6 comments · Fixed by #197
Labels
Type: Support Any questions, information, or general needs around the SDK or GitHub APIs typescript Relevant to TypeScript users only

Comments

@sarvaje
Copy link

sarvaje commented Jun 26, 2020

The property items in the type SearchIssuesAndPullRequestsResponseData doesn't have it's own exported type. it would be nice to have that type defined and exported so we can use in some helpers methods.

For now I'm copy/pasting the code from 'generated/endpoints.ts` and creating the type in my code.

Maybe there is another workaround, but I couldn't find anything.

@sarvaje sarvaje added the Type: Feature New feature or request label Jun 26, 2020
@gr2m
Copy link
Contributor

gr2m commented Jun 26, 2020

you can access all the types you need using the exported Endpoint type, see https://github.com/octokit/types.ts#get-parameter-and-response-data-types-for-a-rest-api-endpoint

For example, to get the response type for PATCH /repos/:owner/:repo/issues/:issue_number, you can do this

const { Endpoints } = require("@octokit/types");
type SearchIssuesAndPullRequestsResponseDataItem = Endpoints["GET /search/issues"]["response"]["data"]["items"][0]

Does that work for you?

I am considering to export the named types, too, but there are a lot of name changes happening right now as part of a big audit. I'll look into that again in 2-3 months

@gr2m gr2m added Type: Support Any questions, information, or general needs around the SDK or GitHub APIs and removed Type: Feature New feature or request labels Jun 26, 2020
@sarvaje
Copy link
Author

sarvaje commented Jun 26, 2020

@gr2m thanks for your quick response.

Only one comment about your type, it is missing the ["response"] part.

This type is the one that works for me:

type SearchItem = Endpoints['GET /search/issues']['response']['data']['items'][0];

Thanks for your help, it would be very nice see the types named in a few months :)

@gr2m
Copy link
Contributor

gr2m commented Jun 27, 2020

Thank you, I fixed it in my example

@gr2m gr2m added the typescript Relevant to TypeScript users only label Jul 13, 2020
@nturinski
Copy link

This would be a nice feature, but will use the mentioned workaround in the meantime 😃

@gr2m
Copy link
Contributor

gr2m commented Nov 11, 2020

You can now also get it from @octokit/openapi-types, which is directly generated from GitHub's official OpenAPI spec, and it will be soon consumed by @octokit/types (see #161). The response data is defined here:

https://github.com/octokit/openapi-types.ts/blob/main/generated/types.ts#L17873-L17877

But you can import "issue-search-result-item" like this

import { components } from "@octokit/openapi-types"

components["schemas"]["issue-search-result-item"]

Hope that works? I do not plan to add other exports at this point.

@gr2m gr2m closed this as completed Nov 11, 2020
@gr2m gr2m mentioned this issue Nov 30, 2020
6 tasks
@octokitbot
Copy link
Collaborator

🎉 This issue has been resolved in version 6.0.0 🎉

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
Type: Support Any questions, information, or general needs around the SDK or GitHub APIs typescript Relevant to TypeScript users only
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants