RobinBlomberg / kysely-codegen

Generate Kysely type definitions from your database.
MIT License
819 stars 73 forks source link

[Feature] Add a flag to generate types instead of interfaces #146

Closed bakasmarius closed 7 months ago

bakasmarius commented 7 months ago

For projects that use ESLint and have @typescript-eslint/consistent-type-definitions set to use types only, type definitions generated by kysely-codegen will throw errors.

It would be nice to have a CLI flag that lets the user choose whether the generated definitions will be saved as types or interfaces.

I would be more than happy to try and make a PR for this tomorrow.

Upvote & Fund

Fund with Polar

RobinBlomberg commented 7 months ago

Hi! I've thought about this before, and I decided that I didn't like the idea of being able to customize the kysely-codegen output too much. The reason is that this creates a potential rabbit hole of trying to match user expectations of what to be able to customize, e.g. formatting, line lengths, Prettier rules, ESLint rules, imports/exports etc.

In my opinion, there are better ways to handle this case:

  1. Ignore linting/formatting for this file (my recommendation). This is how I think all auto-generated files should be handled, as they should not be touched by humans anyway.
  2. If you really want to enable linting/formatting for this file, I would recommend using ESLint --fix to automatically resolve the issue. As far as I can see, consistent-type-definitions should be auto-fixable.

If there is some use case I'm not taking into account, I'd be happy to hear it!

bakasmarius commented 7 months ago

Hi, thanks for your answer and suggestions! I went with option #2 to run ESLint and prettier on the generated file, I'm wondering why I didn't think of that myself 😄

RobinBlomberg commented 7 months ago

Great! 🙌