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

feat(types): type $fetch to match json serialization output #1002

Merged
merged 6 commits into from
Feb 28, 2023

Conversation

mahdiboomeri
Copy link
Contributor

@mahdiboomeri mahdiboomeri commented Feb 27, 2023

πŸ”— Linked issue

resolves #804, resolves #1000

❓ Type of change

  • πŸ“– Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

This PR transforms the output type of $Fetch to better match what JSON.stringify returns (using trpc and remix implementation).

This is potentially a breaking change.

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@codecov
Copy link

codecov bot commented Feb 27, 2023

Codecov Report

Merging #1002 (e405cbb) into main (d83f2b6) will decrease coverage by 0.13%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main    #1002      +/-   ##
==========================================
- Coverage   67.79%   67.66%   -0.13%     
==========================================
  Files          60       60              
  Lines        6133     6161      +28     
  Branches      692      692              
==========================================
+ Hits         4158     4169      +11     
- Misses       1966     1982      +16     
- Partials        9       10       +1     
Impacted Files Coverage Ξ”
src/types/fetch.ts 100.00% <100.00%> (ΓΈ)
src/build.ts 44.62% <0.00%> (-1.45%) ⬇️
src/rollup/plugins/esbuild.ts 54.41% <0.00%> (+1.07%) ⬆️
src/presets/lagon.ts 35.71% <0.00%> (+4.76%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Copy link
Member

@pi0 pi0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

πŸ’―

@pi0 pi0 requested a review from danielroe February 28, 2023 10:14
src/types/serialize.ts Outdated Show resolved Hide resolved
Copy link
Member

@danielroe danielroe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really great.

I only have one suggestion, so we can avoid the super-permissive object type. Otherwise πŸ‘Œ

@mahdiboomeri
Copy link
Contributor Author

@danielroe Thanks πŸ’š, I've also updated the tests. It should be ready to go.

@pi0 pi0 merged commit fe6e579 into nitrojs:main Feb 28, 2023
@mahdiboomeri mahdiboomeri deleted the feat/serialize-fetch branch February 28, 2023 11:42
@danielroe
Copy link
Member

@mahdiboomeri Just to let you know we had to revert part of this as a hotfix owing to increased type complexity: see #1050. If you have any ideas, a PR would be most welcome πŸ™

@danielroe danielroe mentioned this pull request Mar 14, 2023
@mahdiboomeri
Copy link
Contributor Author

@danielroe I think moving Serialize (and Simplify) to nitro-routes.d.ts can help. I did a quick experiment and it seems like it improves type checking duration.

Before:
Screenshot 2023-03-15 at 20-00-53 trace json (1 MB) - Perfetto UI

After:
Screenshot 2023-03-15 at 20-00-33 trace json (1 MB) - Perfetto UI

Is there any reproduction on this?

Copy link
Member

Previously, it reproduced in the Nuxt test:types check.

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.

Auto infer types from .toJSON if property exisits Improve type-safety of $Fetch
4 participants