RobinBlomberg / kysely-codegen

Generate Kysely type definitions from your database.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

bakasmarius opened this issue · comments

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

  • We're using Polar.sh so you can upvote and help fund this issue.
  • We receive the funding once the issue is completed & confirmed by you.
  • Thank you in advance for helping prioritize & fund our backlog.
Fund with Polar

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!

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 😄

Great! 🙌