typescript: unable to import QueryBuilder interface
See original GitHub issueEnvironment
Knex version: 0.95.11 Typescript version: 4.4.3
Bug
Hi,
I’m unsure how to import a QueryBuilder generic interface? (or anything from Knex namespace defined in index.d.ts
?)
as far as I understand the typing:
import { Knex } from 'knex'
will import an interface representing an active connection, knex instance.
import { knex } from 'knex'
imports an initialization function that returns an object conforming to a Knex interface mentioned above
yet I’m trying to get to a QueryBuilder<TRecord, TResult>
😃
I’m writing chainable query modifying functions used for pagination, universal filtering etc. of type:
(QueryBuilder) => QueryBuilder
Knex interface is quite similar to QueryBuilder so I suppose that most people use this? But I need an actual QueryBuilder for generic typing of my returns, and clone() etc calls that are not available on Knex
Thanks!
edit, my tsconfig if relevant
{
"include": ["src", "test"],
"compilerOptions": {
"lib": ["es2020"],
"module": "ESNext",
"target": "es2020",
"importHelpers": true,
"declaration": true,
"sourceMap": true,
"rootDir": "./src",
"strict": true,
"resolveJsonModule": true,
"noImplicitAny": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"strictPropertyInitialization": true,
"noImplicitThis": true,
"alwaysStrict": true,
"noUnusedLocals": false,
"noUnusedParameters": false,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"moduleResolution": "node",
"baseUrl": "./",
"paths": {
"*": ["src/*", "node_modules/*"]
},
"esModuleInterop": true
}
}
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:5
Top GitHub Comments
I’ve tried with exactly your version of typescript and your tsconfig.json, and its working. (idk maybe i miss something)
It definitely imported namespace here
Actually you are right @maximelkin, I wasn’t sure how ts is supposed to handle interfaces, functions and namespaces with the same name.
I created a new project just to test this (https://github.com/leshy/knextest) it seems that the issue is somewhere deeper in my ts stack (I’m using tsdx for ts dev env management https://tsdx.io/)
running
tsdx compile
produces the error I’m mentioning, yet running tsc manually compiles without issues.Thanks for the help and sorry for confusion 😃 I’ll investigate my stack and close this now
edit, Investigating this further under tsdx project, https://github.com/jaredpalmer/tsdx/issues/1095