mrjono1 / joi-to-typescript

Convert Joi Schemas to TypeScript interfaces
MIT License
124 stars 39 forks source link

Replace `{}` with `Record<string, never>` #410

Closed cmaster11 closed 7 months ago

cmaster11 commented 7 months ago

I have apparently fallen victim to a common TS fallacy, where I assumed {} represented an empty object when instead it represents any non-nullish value. After ESLint started complaining, I discovered a new world 😅

https://www.totaltypescript.com/the-empty-object-type-in-typescript

Google thinks a good approach is to use Record<string, never>, which prevents any field from being added to the record, mimicking a truly empty object.

There are approaches with symbols and so on, but I feel this is a pretty straightforward easy way to at least prevent on the surface any issues.

codecov[bot] commented 7 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Comparison is base (48fe784) 98.79% compared to head (6322bf0) 98.79%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #410 +/- ## ======================================= Coverage 98.79% 98.79% ======================================= Files 9 9 Lines 580 580 Branches 224 224 ======================================= Hits 573 573 Misses 7 7 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.