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

Fixes #312 Add typed json response #437

Merged
merged 6 commits into from
Jun 23, 2022

Conversation

TeraNovaLP
Copy link
Contributor

@TeraNovaLP TeraNovaLP commented Apr 20, 2022

Hey,

to fix the issue, I implemented an axios like solution with an extended response object. With this solution, there should be no breaking changes either.

Fixes #312

@sindresorhus
Copy link
Owner

This needs a type test to prove that your change actually resolves the issue.

@TeraNovaLP
Copy link
Contributor Author

@sindresorhus I'm not quite sure how to do this. I don't see a way to automatically check the type when they are gone at runtime. Sorry if I overlook something right now. 😅

@TeraNovaLP
Copy link
Contributor Author

@sindresorhus Sorry to bother you, but I can't continue without an answer to my previous question.

@sindresorhus
Copy link
Owner

You should test at compile-time. The Ky tests are in TypeScript, so you can use type assertions. For example, using https://github.com/mmkal/ts/tree/master/packages/expect-type

@TeraNovaLP
Copy link
Contributor Author

@sindresorhus I have added a type check to the tests with the mentioned library. Could you please have a look at my changes? Thanks

@sindresorhus sindresorhus merged commit cff4c7a into sindresorhus:main Jun 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature request] Typing JSON response using TS generics
2 participants