The "@types/dd-trace" library defines a single variable called trace in the type definition for the "dd-trace" library.
declare var trace: TraceProxy;
export = trace;
declare class TraceProxy extends Tracer {
/**
* Initializes the tracer. This should be called before importing other libraries.
*/
init(options?: TracerOptions): this;
// A bunch of other irrelevant code.
}
Attempting to import this in my code has proven to be challenging. When trying to assign ddTrace.init() to a boolean, TypeScript correctly identifies the type as 'TraceProxy'. However, various import attempts have failed:
import { TraceProxy } from "dd-trace"
results in an error saying
node_modules/@types/dd-trace"' has no exported member 'TraceProxy'.
import { init, trace } from "dd-trace"
const tracer: trace = init()
The import is successful, but the declaration fails with 3:15: cannot find name "trace"
Multiple other variations also fail:
const tracer: trace.trace = init()
const tracer: trace.TraceProxy = init()
const tracer: trace.Tracer = init()
const tracer: TraceProxy = init()
const tracer: Tracer = init()
Even importing the module itself fails:
import * as ddTrace from "dd-trace"
const tracer: ddTrace = ddTrace.init()
yielding Cannot find name 'ddTrace'.
on line 3.
Other attempts like:
import * as ddTrace from "dd-trace"
const tracer: ddTrace.TraceProxy = ddTrace.init()
result in Cannot find namespace 'ddTrace'.
One suggested solution was:
import trace from "dd-trace"
const tracer: trace = trace.init()
However, this fails with
@types/dd-trace/index"' has no default export.
How can I correctly declare the type definition and import it? I'm using the latest version of TypeScript and compiling by running
./node_modules/.bin/tsc myfile.ts
.