sandulat / routes-gen

Framework agnostic routes typings generator. Remix ☑️ SolidStart ☑️
MIT License
281 stars 12 forks source link

fix: change the empty object type {} to use TS Record utility type #21

Closed aniravi24 closed 2 years ago

aniravi24 commented 2 years ago

To use the more accurate type based on typescript/eslint's recommendations, The generated type when there's no param was changed to Record<string, never>

 Don't use `{}` as a type. `{}` actually means "any non-nullish value".
- If you want a type meaning "any object", you probably want `Record<string, unknown>` instead.
- If you want a type meaning "any value", you probably want `unknown` instead.
- If you want a type meaning "empty object", you probably want `Record<string, never>` instead

https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/docs/rules/ban-types.md

For example, this is valid in the current main branch

image

But once it's changed, now it throws an error

image

However, this is still valid as expected

image

aniravi24 commented 2 years ago

@sandulat we enabled a plugin in our project that triggered this error, thought I should change it here so it works for everyone! The Record utility type has been around since TS 2.1 so it should work.

IgnisDa commented 2 years ago

@sandulat Can this be merged please?

sandulat commented 2 years ago

Sorry for the delay @aniravi24! This is now released under routes-gen 0.5.1. https://github.com/sandulat/routes-gen/releases/tag/v0.5.1 https://www.npmjs.com/package/routes-gen/v/0.5.1

cc @IgnisDa

sandulat commented 2 years ago

Thank you very much @aniravi24!

aniravi24 commented 2 years ago

@sandulat awesome, thank you!