jfgodoy / knex-postgis

postgis extension for knex
MIT License
183 stars 25 forks source link

Usage with Typescript #35

Closed jsonmaur closed 5 years ago

jsonmaur commented 5 years ago

Can't seem to use this library with Typescript cause it looks like the DefinitelyTyped definitions are out of date (don't know if you maintain those or not): https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/knex-postgis

For reference, this is the type error:

Argument of type 'Knex<any, unknown[]>' is not assignable to parameter of type 'Knex'.
  Property 'clone' is missing in type 'Knex<any, unknown[]>' but required in type 'Knex'.

Usage:

const db = knex({ dialect: "postgres" })
const st = knexPostgis(db)
jfgodoy commented 5 years ago

hi @jsonmaur, sorry, I don't mantain that project and I haven't used typescript to be of any help.

I you need to make a PR to this project to fix the issue I'll be happy to review.

ctusch commented 5 years ago

Funnily I ran into the exact same problem yesterday too. The problem is that @types/knex-postgis comes with its own knex dependency locked at ^0.16.1. Since knex is still doing 0.x releases that means npm install won't install 0.17.0 or higher but instead @types/knex-postgis gets its own local knex dependency whose typings are outdated compared to the newer knex typings which get passed to the KnexPostgis function.

Possible workarounds without updating the typings (which are missing the function definitions mentioned in the change log but which I don't need):

Edit: I removed the cast to any as a possible workaround since it would lead to similar problems with further usage.

jfgodoy commented 5 years ago

hi guys, I created a pull request #37 that adds basic support for typescript. To my understanding this will fix this issue. I would like you to review this PR and comment it if it is good enough before merge. You have more experience working with typescript so I would thank you if you can help me to improve the solution.

ctusch commented 5 years ago

Thank you! I'll have a look at it.

jfgodoy commented 5 years ago

I just publish v0.10.0 which includes basic support for typescript. I will close this issue for now, but feel free to open it if you have any problem with the new release.