Matthew Holmes
Matthew Holmes

Reputation: 803

Typescript definitions: how to declare class inside class

I have two javascript classes, one called AmazingMultiplier and one called AmazingAdder. I am struggling with writing typescript definition of AmazingAdder. The javascript file, looks like the following:

MyModule.AmazingAdder = function(options){
     //some amazing code

 };

MyModule.AmazingAdder.Statuses={
   success: 1,
   failure: 2
};

I am not sure how to declare the statuses object in my typescript definitions file. My d.ts file looks like:

declare module MyModule
{
  export class AmazingMultiplier
  {
       result: number;
       constructor(params: any?)
  }

 export class AmazingAdder
  {
     constructor(params: any?)
     class Statuses
     {
        success: number,
        failure: number
     }
  }

}

However I get unexpected token for 'class' where Statuses are defined. Any assistance would be appreciated. I have read through the tutorials but don't understand how I would do this.

Upvotes: 1

Views: 1438

Answers (1)

David Sherret
David Sherret

Reputation: 106640

You can create a class and module with the same name. Also, you'll want to use an enum for Statuses:

declare module MyModule {
    class AmazingAdder {
        constructor(params?: any);
    }
    module AmazingAdder {
        enum Statuses {
            success = 1,
            failure = 2,
        }
    }
}

Upvotes: 3

Related Questions