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

fix: tighten schema definition types #102

Merged
merged 2 commits into from
Jul 28, 2023
Merged

fix: tighten schema definition types #102

merged 2 commits into from
Jul 28, 2023

Conversation

danielroe
Copy link
Member

πŸ”— Linked issue

nuxt/nuxt#22340

❓ Type of change

  • πŸ“– Documentation (updates to the documentation, readme, or JSdoc annotations)
  • 🐞 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)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

We currently have an issue with newer typescript versions whereby $resolve (and similar 'magic' keys) are not being typed correctly because they could also be equally well typed with any. This makes a change to SchemaDefinition types that removes the any signature in favour of explicit JSValue types (but only for keys that do not match $resolve, etc.).

This increases type safety and may result in an error when an unknown property is assigned to a schema value. But nevertheless this is worth testing to ensure no (unintended) regressions.

πŸ“ Checklist

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

@danielroe danielroe added the bug Something isn't working label Jul 26, 2023
@danielroe danielroe requested a review from pi0 July 26, 2023 09:37
@danielroe danielroe self-assigned this Jul 26, 2023
src/types.ts Show resolved Hide resolved
@danielroe
Copy link
Member Author

FYI: these were the changes necessary to get migrate Nuxt to the new definition: nuxt/nuxt@6604ed7.

I don't believe these were the result specifically of this change but due to greater strictness in latest TS version.

As well as the changes in this PR, I would suggest we also relax the InputObject types when used within applyDefaults and resolveSchema - ie. at the moment it is asserting that the input object must have a key signature, but I think we should not do so.

@codecov
Copy link

codecov bot commented Jul 28, 2023

Codecov Report

Merging #102 (a17175e) into main (347c312) will not change coverage.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##             main     #102   +/-   ##
=======================================
  Coverage   88.00%   88.00%           
=======================================
  Files           8        8           
  Lines        1167     1167           
  Branches      270      270           
=======================================
  Hits         1027     1027           
  Misses        140      140           
Files Changed Coverage Ξ”
src/types.ts 100.00% <100.00%> (ΓΈ)

@pi0 pi0 merged commit 3b91d06 into main Jul 28, 2023
@pi0 pi0 deleted the fix/recursive-types branch July 28, 2023 09:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants