Skip to content

client["/endpoint"].GET style call pattern to enable go-to-definition #1526

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

Closed
1 task done
tonyxiao opened this issue Jan 30, 2024 · 3 comments
Closed
1 task done
Assignees
Labels
enhancement New feature or request openapi-fetch Relevant to the openapi-fetch library PRs welcome PRs are welcome to solve this issue! tricky Complex problem which requires deep knowledge of TS, OpenAPI, this project, or all three

Comments

@tonyxiao
Copy link

tonyxiao commented Jan 30, 2024

Description

Navigating from call site to docs (aka generated typing) today is quite inconvenient as vscode is not able to navigate from the path argument parameter to the type def. I would love to be able to use cmd+click to be able to go straight to the generated types for the specific endpoint. This is similar to how trpc would work

Proposal

Before

client.GET('/endpoint', { params: {} })

After

client['/endpoint'].GET({ params: {} })

This way you can cmd+click on the /endpoint part in VSCode to go straight to defintion

We can keep both call styles too (just like TRPC) for backward compat.

Checklist

@tonyxiao tonyxiao added enhancement New feature or request PRs welcome PRs are welcome to solve this issue! openapi-fetch Relevant to the openapi-fetch library labels Jan 30, 2024
@tonyxiao tonyxiao changed the title client["/endpoint"].GET style call pattern client["/endpoint"].GET style call pattern to enable go-to-definition Jan 30, 2024
@drwpow
Copy link
Contributor

drwpow commented Feb 14, 2024

I’m all for better Intellisence and VS Code integration, but how would the runtime work? Would client have to be a getter method? And would this be able to use openapi-typescript’s types as-generated? I’d be curious to see a PoC on how this could work from both a runtime and type inference side, even with a simple schema.

@tonyxiao
Copy link
Author

tonyxiao commented Feb 15, 2024

Sure. This it how it is used.

https://github.com/trpc/trpc/blob/44a1b58a3f21dae230cf290a71d93614d469e63b/examples/next-minimal-starter/src/pages/index.tsx#L8

This is how trpc implements it. I believe it uses native javascript Proxy object to accomplish it with explicitly casted typing

https://github.com/trpc/trpc/blob/44a1b58a3f21dae230cf290a71d93614d469e63b/packages/client/src/createTRPCClient.ts#L126-L145

And I don't see any reason to change openapi-typescript. I believe it should work as is.

@drwpow drwpow added the tricky Complex problem which requires deep knowledge of TS, OpenAPI, this project, or all three label Jun 24, 2024
@gzm0
Copy link
Contributor

gzm0 commented Aug 10, 2024

This is fixed in #1791 / openapi-fetch 0.11.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request openapi-fetch Relevant to the openapi-fetch library PRs welcome PRs are welcome to solve this issue! tricky Complex problem which requires deep knowledge of TS, OpenAPI, this project, or all three
Projects
Development

No branches or pull requests

4 participants