question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

typescript: unable to import QueryBuilder interface

See original GitHub issue

Environment

Knex version: 0.95.11 Typescript version: 4.4.3

@lorefnon

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:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:5

github_iconTop GitHub Comments

1reaction
maximelkincommented, Oct 24, 2021

I’ve tried with exactly your version of typescript and your tsconfig.json, and its working. (idk maybe i miss something)

Namespace ‘“…”.Knex’ has no exported member ‘QueryBuilder’.

It definitely imported namespace here

0reactions
leshycommented, Oct 25, 2021

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Property 'customSelect' does not exist on type 'Knex<any ...
I want to add a new method to knex in typescript as written in the docs (search "Extending Query Builder"). So I create...
Read more >
TypeORM - Amazing ORM for TypeScript and JavaScript (ES7 ...
Elegant-syntax, flexible and powerful QueryBuilder. Left and inner joins. Proper pagination for queries using joins. Query caching. Streaming raw results.
Read more >
kysely
Kysely. Kysely (pronounce “Key-Seh-Lee”) is a type-safe and autocompletion-friendly typescript SQL query builder. Inspired by knex.
Read more >
Using TypeORM's QueryBuilder in NestJS - LogRocket Blog
It's powerful, enforces best practices, and uses the latest JavaScript features. It also has default support for TypeScript and uses TypeORM ...
Read more >
Usage With TypeScript - Redux Toolkit
TypeScript ; JavaScript. // Need to use the React-specific entry point to allow generating React hooks import { createApi, fetchBaseQuery } ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found