You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to extend knex with a function that would return something that is not the queryBuilder instance. I guess the same way that .toSQL() returns an object that is not the queryBuilder.
However I'm having a typescript error. I'm not a typescript expert and I wonder if I can solve this problem or if a typescript change is needed in the knex library. I was expecting to be able to return anything.
Argumentoftype<TRecordextends{}=any,TResultextends{}=unknown[]>(this: QueryBuilder<TRecord,TResult>)=>Sql
is notassignabletoparameteroftype<TRecordextends{}=any,TResultextends{}=unknown[]>(this: QueryBuilder<TRecord,TResult>,
...args: any[])=>QueryBuilder<TRecord,TResult>|Promise<Resolve<TResult>|QueryBuilder<TRecord|TResult,any>>Type 'Sql' is not assignable to type 'QueryBuilder<TRecord,TResult>|Promise<Resolve<TResult>|QueryBuilder<TRecord|TResult,any>>ts(2345)
Can replicate, no nicer solution than adding an as any after the return. Good news is that it's not the worst as any in history, it wouldn't infer the return type anyway. For that you can just augment knex type
Environment
Knex version: 3.1.0
Bug
Problem
I'm trying to extend knex with a function that would return something that is not the queryBuilder instance. I guess the same way that .toSQL() returns an object that is not the queryBuilder.
However I'm having a typescript error. I'm not a typescript expert and I wonder if I can solve this problem or if a typescript change is needed in the knex library. I was expecting to be able to return anything.
My code:
The typescript error:
Reproduce error
You can test the code there: https://replit.com/@replit77i18/Knex-extend-typescript-error#index.ts
The text was updated successfully, but these errors were encountered: