-
-
Notifications
You must be signed in to change notification settings - Fork 529
Please rename .del
to .delete
because of TS
#1218
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
Comments
|
I completely forgot about the reserved word. Been forever since I used it. Confusion from using the keyword Another option is to name it |
I encountered this recently and just did /**
* Map HTTP method to the corresponding `openapi-fetch` method.
* @param {string} str
*/
function methodName(str) {
if (str === "delete") return "del";
return str;
} |
Would just like to point out that this is the route SvelteKit took for similar reasons, and you can read the discussion here. Personally, I don't mind the capitalization and agree with the reasoning made there. |
That’s some fantastic prior art and discussion. Thank you for sharing! I’m strongly inclined to copy this pattern (as a breaking change). |
|
Hopefully this is an adequate fix to the issue! 🙂 Marking as closed, but still open to feedback here. |
Thanks for fixing this issue ;). |
Description
I'm using TypeScript and had a hell of a time trying to figure out why my types for
paths
2nd level didn't match the types for the functions oncreateClient
. I believe it's because ofdel
. Wasted 10 hours on this because it's so hard to catch.I wrapped
createClient
, so I could use it in a React context withreact-query
through a helper hook. But I kept getting errors doingopenapiFetchClient[method]
wheremethod
waspaths[Path]
.TS was erroring, but the message was so convoluted. Even looking at the types, I couldn't tell what was wrong because I didn't have a
delete
in mypaths
only that TS wasn't happy about it.Proposal
The types created from OpenAPI-TypeScript should 100% match the function names in
createClient
to allow easier wrapping ofcreateClient
with type-safety.Please rename
.del
to.delete
.I had to rewrite the type of
createClient
to get it working (before I knew about the.del
function). Because of rewriting that type, I ran into an issue wheredel
didn't work, but now TS didn't error, and react-query ate the runtime error.Checklist
The text was updated successfully, but these errors were encountered: