Serge van den Oever
Serge van den Oever

Reputation: 4392

TypeScript definition file for JavaScript class without having to declare all members

I would like to create a typescript definition for a big JavaScript class without adding all its members, I would like it to be of type "any". For example:

ContainerSurface.d.ts:

declare class ContainerSurface {
}
export = ContainerSurface;

And just use the class and call any members on it without having them "declared", like:

MyClass.ts:

import ContainerSurface = require('ContainerSurface');

class MyClass extends ContainerSurface {
    constructor(options) {
        super(options);
        var a: ContainerSurface({option: "test"});
        a.add("test");
    }
}

export = MyClass;

Upvotes: 2

Views: 3287

Answers (1)

Fenton
Fenton

Reputation: 251022

You can achieve this using the following:

declare var ContainerSurface: any;

export = ContainerSurface;

This is the first step in my Definition Files Made Easy process - so you can gradually add types over time using this as the starting point.

Step two is to loosely specify properties and methods:

declare class ContainerSurface {
    myMethod: any;
    myProperty: any;
}

export = ContainerSurface;

Grab any quick wins, like primitive types, and just add the stuff you actually use to start off with.

Upvotes: 2

Related Questions