简体   繁体   中英

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;

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM