Knex types not being inferred
See original GitHub issueEnvironment
Knex version: 3 Database + version: MSQL OS: Linux
Bug
I have 2 projects, both using knex and typescript. Both are open source. One of the two is simply not listening to my Knex table types. My definitions look like this:
declare module 'knex/types/tables' {
interface Principal {
id: number;
identity: string;
type: number;
external_id: string;
nickname: string;
created_at: number;
modified_at: number;
active: number;
}
interface OAuth2Client {
id: number;
client_id: string;
client_secret: string;
allowed_grant_types: string;
user_id: number;
require_pkce: number;
}
interface Tables {
oauth2_clients: OAuth2Client;
principals: Principal;
}
}
I’ve placed this file in my knexfile.ts
, in the file that sets up the knex
global singleton, and in a separate knex-definitions.
Elsewhere in my code, I have code like this:
const result = await db('oauth2_clients')
.select('*')
.where('client_id', clientId);
So far result
is not inferred as OAuth2Client[]
, and I’m not sure what else to share to get close to the root of this.
Issue Analytics
- State:
- Created a year ago
- Comments:5
Top Results From Across the Web
Maintaining type inference when aliasing columns in knex
aList is inferred to be of type { primaryId: number, name: string }[] ... aliasing (so long as we only reference the column...
Read more >Knex Query Builder
We are generally able to infer the result type based on the columns being selected as long as the ... If the query...
Read more >Upgrading from v3 to v4 - MikroORM
This is documentation for MikroORM 4.5, which is no longer actively maintained. ... Without the explicit type, we would infer Object instead of...
Read more >tgriesser/knex - Gitter
What's the point of using the --knexpath flag if config is not inferred ... Instead I'm getting type errors like Raw<any[]> cannot be...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thank you so much for helping me fix this!!
Reference: https://github.com/curveball/a12n-server/pull/385
Also no luck, lol. I also tried making sure that I’m consistently importing knex as
import knex from 'knex'
and remove instances where I didimport { knex } from 'knex'
, because I was worried that somehow Typescript would consider the 2 import paths as separate.Maybe I just need to look at my other project (where this does work!) and reverse engineer it until I find what’s the difference between the two.
Thanks! Well let me know if you ever want a chat about it! I like meeting new people!