简体   繁体   中英

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

I'm trying to use a session helper called connect-session-knex which is obscure enough that it does not have a published typescript definition. So when I try to compile my typescript node project, I get the error,

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

Is there a way to ignore TS for this module only? How do I import it without the TSD? I know knex has a tsd, but the wrapper does not. I'm asking this from a generic standpoint of what to do with libraries without type definitions.

For anyone looking: Compiling typescript when it does not have tsd. Missing tsd. Without tsd.

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

Use var/require instead of import/require . ie

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

Note you should have node.d.ts included for require to be declared.

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

Another suggestion is to start you own .d.ts file as an empty definition file and export the module. Then if you want to get intellisense on the module you can add definitions to it.

eg connect-session-knex.d.ts :

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

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM