When expanding the Express.Request interface in TypeScript, I came across this problem that I want to use the definition of an external library, but I can not import the external library, as this leads to an error →
Error: (4, 28) TS1147: import declarations in the internal module cannot refer to the external module.
Edit: this is a .d.ts file
declare module Express {
import bunyan = require('bunyan'); <-- results in error
export interface Request {
_id: string; <-- this works
log: bunyan.Logger; <-- Here I want to define that it is bunyan.Logger instance;
}
}
Trying to link to bunyan.d.ts ( https://github.com/borisyankov/DefinitelyTyped/blob/master/bunyan/bunyan.d.ts ) There is also a problem because the bunyan module is exported as a string
declare module "bunyan" {
...
}
As such, trying to use it from referenced results in not found.
declare module Express {
export interface Request {
_id: string;
log: bunyan.Logger; <- Error:(8, 18) TS2304: Cannot find name 'bunyan'.
}
}
TL; dg; How to extend the definition of an interface using the definition of an external module.