A few months back, I crafted a basic TS declaration library known as @types/datadog-winston
which is available for viewing here. After using the typings locally and adding them to the DefinitelyTyped repository with successful verifications and tests from the team, my library was successfully published.
Recently, while trying to implement it, I encountered an issue. Upon trying to include my new DatadogWinston(options)
object in the list of TransportStream[]
as another transport for winston
, an error popped up:
Services/Sandbox/sandbox/node_modules/@types/datadog-winston/index.d.ts:19:48 - error TS2339: Property 'TransportStream' does not exist on type 'type TransportStream'.
declare class DatadogWinston extends Transport.TransportStream {
~~~~~~~~~~~~~~~
Services/Sandbox/sandbox/src/logging/logger.ts:32:21 - error TS2345: Argument of type 'DatadogWinston' is not assignable to parameter of type 'TransportStream'.
Type 'DatadogWinston' is missing the following properties from type 'TransportStream': writable, writableHighWaterMark, writableLength, _write, and 24 more.
transports.push(transport);
~~~~~~~~~
Upon further investigation into how other winston transports function, I noticed that each import the module winston-transport
differently.
They did it like this:
import * as TransportStream from "winston-transport";
declare class Graylog2Transport extends TransportStream {
constructor(options?: Graylog2Transport.TransportOptions);
}
...
Contrastingly, winston-loggly-bulk did it like this:
import TransportStream = require('winston-transport');
By switching from the Graylog2
style to the winston-loggly-bulk
style, implementing
import TransportStream = require("winston-transport");
All my build errors disappeared. My confusion lies in the differences between these methods of importing modules. While CommonJS used const lib = require('mylib')
and ES6 introduced import { Thing } from 'mylib'
, what exactly is the purpose of import MyLib = require('mylib')
in this particular scenario? The various nuances between these techniques are proving challenging for me to grasp.
UPDATE
I attempted to utilize the winston-graylog2
library and encountered the same error! It seems to relate to my local development environment. I am using the latest version of TypeScript (v3.7.5) and facing this issue in both VS Code (with TS Server extension) and when directly running a tsc build from the CLI.