How to import a library into a node without a Typescript / TSD definition?

I am trying to use a session helper called connect-session-knex that is not hidden enough that it does not have a published typescript definition. So when I try to compile the typescript node project, I get an error message,

error TS2307 Cannot find module 'connect-session-knex' 

Is there a way to ignore TS only for this module? How to import it without TSD? I know knex has tsd, but no wrapper. I ask about this from a general point of view of what to do with libraries without specifying types.

For all who are looking for: Compilation of typescript when it does not have tsd. Missing. Without a theater.

+7
module package typescript tsd
source share
2 answers

error TS2307 Cannot find module 'connect-session-knex' Is there a way to ignore TS only for this module? How to import it without TSD?

Use var/require instead of import/require . those.

 var csk = require('connect-session-knex'); 

Note that you must include node.d.ts for require .

Also: https://basarat.gitbooks.io/typescript/content/docs/node/nodejs.html

+12
source share

Another suggestion is to run your own .d.ts file as an empty definition file and export the module. Then, if you want to get intellisense in a module, you can add definitions to it.

eg. connect-session-knex.d.ts :

 // declare module
 declare module "connect-session-knex" {

 }
+5
source share

All Articles