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

The generic of the APIRoute type does not specify the second generic type of APIContext. #9612

Closed
1 task done
ivaaaaann opened this issue Jan 4, 2024 · 2 comments · Fixed by #9618
Closed
1 task done
Labels
- P2: nice to have Not breaking anything but nice to have (priority) feat: typescript Related to TypeScript (scope)

Comments

@ivaaaaann
Copy link
Contributor

Astro Info

Astro                    v4.1.0
Node                     v18.16.0
System                   macOS (arm64)
Package Manager          yarn
Output                   static
Adapter                  none
Integrations             @astrojs/react
                         @astrojs/mdx
                         @astrojs/sitemap

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

While typing through the APIRoute type to create an API based on the pages folder, the params parameter was not typed, so I checked the type and found that the APIRoute type was receiving one less generic.

  • The code I was facing the problem with is the screenshot below.
스크린샷 2024-01-05 오전 3 26 53
  • Even if you type the parameters separately, the type will be broken.
스크린샷 2024-01-05 오전 3 25 34
  • The problem occurred because the APIRoute type only received one generic, and only one of the two generics of the APIContext type was set.
스크린샷 2024-01-05 오전 2 53 17
  • The second generic of the APIContext type is just typing params 🥲
스크린샷 2024-01-05 오전 2 55 52
  • So adding a second generic to APIRoute solves the problem. I tried changing astro.d.ts in my personal project and it worked well. Would it be okay if I contributed by uploading a PR related to this?

What's the expected result?

  • explained above

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-eyozpb?file=src%2Fpages%2Fapi%2Fblog%2Fviews%2F%5Bslug%5D.ts

Participation

  • I am willing to submit a pull request for this issue.
@github-actions github-actions bot added the needs triage Issue needs to be triaged label Jan 4, 2024
@lilnasy
Copy link
Contributor

lilnasy commented Jan 4, 2024

Thanks for looking into it! Seems like a reasonable follow-up to adding the first generic to APIRoute.

@lilnasy lilnasy added - P2: nice to have Not breaking anything but nice to have (priority) feat: typescript Related to TypeScript (scope) and removed needs triage Issue needs to be triaged labels Jan 4, 2024
@ivaaaaann
Copy link
Contributor Author

@lilnasy Thanks for checking out! Could I possibly upload a PR related to this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P2: nice to have Not breaking anything but nice to have (priority) feat: typescript Related to TypeScript (scope)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants