unjs / untyped

Generate types and markdown from a config object.
https://untyped.unjs.io/
MIT License
446 stars 19 forks source link

fix: tighten schema definition types #102

Closed danielroe closed 1 year ago

danielroe commented 1 year ago

πŸ”— Linked issue

https://github.com/nuxt/nuxt/pull/22340

❓ Type of 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

danielroe commented 1 year ago

FYI: these were the changes necessary to get migrate Nuxt to the new definition: https://github.com/nuxt/nuxt/pull/22340/commits/6604ed7858b5ea588363fb08aa9f50f008415bc2.

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[bot] commented 1 year ago

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%> (ΓΈ)