kriasoft / knex-types

Generate TypeScript definitions (types) from a PostgreSQL database schema.
MIT License
63 stars 21 forks source link

How to use this package with the official documentation? #21

Open winston0410 opened 2 years ago

winston0410 commented 2 years ago

Thank you so much for your effort for writing this package, it is awesome! But it would be even better if it can support the official typing usage for Knex.

This is the official way for defining table types for Knex:

https://knexjs.org/#typescript-support

But right now knex-types would exports an enum of Table, which we will still need to import the whole file to get the type. Can it generate a .d.ts instead, and define everything under module declare module 'knex/types/tables'?

evert commented 2 years ago

Curious how others have solved this!

bhenderson commented 1 month ago

old issue, but you could probably set prefix and suffix options

updateTypes(db, {
  output: 'db.d.ts',
  prefix: `declare module 'knex/types/tables' {`
  suffix: '}'
})