DeyyyFF
DeyyyFF

Reputation: 953

Typescript - define a type for external AMD Module

I am loading a non-typescript amd module (written in javascript, not compiled from ts) inside a typescript module using require:

var worker = require('worker');

the worker module exports several constructor-functions.

now I want to make some type definitions (for example as the backbone.d.ts)

module WorkerModule {
    interface IResult {
        amount(): number;
    }
    interface IWorker {
        work();
        getResult(): IResult;
    }
    interface OtherWorker extends IWorker {
        workMore();
    }
}

How can I tell TSC that worker is a WorkerModule. thanks for any help.

Upvotes: 2

Views: 764

Answers (1)

Fenton
Fenton

Reputation: 250882

You can type your worker variable:

var worker: IWorker = require('worker');

This will provide type-checking on the worker variable.

Upvotes: 2

Related Questions