How to augment class declared but not exported on Typescript module











up vote
2
down vote

favorite












The hubot type definitions have the following class:



declare namespace Hubot {
// ...

class Message {
user: User;
text: string;
id: string;
}

// ...
}

// Compatibility with CommonJS syntax exported by Hubot's CoffeeScript.
// tslint:disable-next-line export-just-namespace
export = Hubot;
export as namespace Hubot;


https://github.com/DefinitelyTyped/DefinitelyTyped/blob/a6b283d1d43d8c7c82a4a4e22d0fc27c9964154c/types/hubot/index.d.ts#L18-L22



I want to augment the Message class from my code, inside a hubot.d.ts file I've written:



import * as hubot from 'hubot';

declare namespace Hubot {
export class Message {
mentions: string
}
}


But it does not works:
enter image description here



The hubot.d.ts file is included in the code by having



  "files": ["types/custom/hubot.d.ts"]


In the tsconfig.json file.



What I'm missing? Any way to do that?










share|improve this question


























    up vote
    2
    down vote

    favorite












    The hubot type definitions have the following class:



    declare namespace Hubot {
    // ...

    class Message {
    user: User;
    text: string;
    id: string;
    }

    // ...
    }

    // Compatibility with CommonJS syntax exported by Hubot's CoffeeScript.
    // tslint:disable-next-line export-just-namespace
    export = Hubot;
    export as namespace Hubot;


    https://github.com/DefinitelyTyped/DefinitelyTyped/blob/a6b283d1d43d8c7c82a4a4e22d0fc27c9964154c/types/hubot/index.d.ts#L18-L22



    I want to augment the Message class from my code, inside a hubot.d.ts file I've written:



    import * as hubot from 'hubot';

    declare namespace Hubot {
    export class Message {
    mentions: string
    }
    }


    But it does not works:
    enter image description here



    The hubot.d.ts file is included in the code by having



      "files": ["types/custom/hubot.d.ts"]


    In the tsconfig.json file.



    What I'm missing? Any way to do that?










    share|improve this question
























      up vote
      2
      down vote

      favorite









      up vote
      2
      down vote

      favorite











      The hubot type definitions have the following class:



      declare namespace Hubot {
      // ...

      class Message {
      user: User;
      text: string;
      id: string;
      }

      // ...
      }

      // Compatibility with CommonJS syntax exported by Hubot's CoffeeScript.
      // tslint:disable-next-line export-just-namespace
      export = Hubot;
      export as namespace Hubot;


      https://github.com/DefinitelyTyped/DefinitelyTyped/blob/a6b283d1d43d8c7c82a4a4e22d0fc27c9964154c/types/hubot/index.d.ts#L18-L22



      I want to augment the Message class from my code, inside a hubot.d.ts file I've written:



      import * as hubot from 'hubot';

      declare namespace Hubot {
      export class Message {
      mentions: string
      }
      }


      But it does not works:
      enter image description here



      The hubot.d.ts file is included in the code by having



        "files": ["types/custom/hubot.d.ts"]


      In the tsconfig.json file.



      What I'm missing? Any way to do that?










      share|improve this question













      The hubot type definitions have the following class:



      declare namespace Hubot {
      // ...

      class Message {
      user: User;
      text: string;
      id: string;
      }

      // ...
      }

      // Compatibility with CommonJS syntax exported by Hubot's CoffeeScript.
      // tslint:disable-next-line export-just-namespace
      export = Hubot;
      export as namespace Hubot;


      https://github.com/DefinitelyTyped/DefinitelyTyped/blob/a6b283d1d43d8c7c82a4a4e22d0fc27c9964154c/types/hubot/index.d.ts#L18-L22



      I want to augment the Message class from my code, inside a hubot.d.ts file I've written:



      import * as hubot from 'hubot';

      declare namespace Hubot {
      export class Message {
      mentions: string
      }
      }


      But it does not works:
      enter image description here



      The hubot.d.ts file is included in the code by having



        "files": ["types/custom/hubot.d.ts"]


      In the tsconfig.json file.



      What I'm missing? Any way to do that?







      javascript typescript types






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 16 at 21:05









      JCM

      5,53533857




      5,53533857
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          3
          down vote



          accepted










          hubot.d.ts should contain:



          // This import serves no purpose except to make the file a module
          // (so that the following statement is a module augmentation rather
          // than a module declaration) and could be replaced with `export {}`.
          import * as hubot from 'hubot';

          declare module "hubot" {
          interface Message {
          mentions: string
          }
          }


          A module augmentation is needed to add declarations to the hubot module. Since the Hubot namespace is assigned as the export of the module, any augmentations made to the module will target that namespace directly; writing another namespace Hubot { ... } in the augmentation would create a nested namespace, which isn't what you want. Finally, declaring a class gives a "duplicate identifier" error, while declaring an interface is sufficient to add properties.






          share|improve this answer





















          • Thanks, worked perfectly, and thanks for the explanation. It makes sense now.
            – JCM
            2 days ago











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














           

          draft saved


          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53345357%2fhow-to-augment-class-declared-but-not-exported-on-typescript-module%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          3
          down vote



          accepted










          hubot.d.ts should contain:



          // This import serves no purpose except to make the file a module
          // (so that the following statement is a module augmentation rather
          // than a module declaration) and could be replaced with `export {}`.
          import * as hubot from 'hubot';

          declare module "hubot" {
          interface Message {
          mentions: string
          }
          }


          A module augmentation is needed to add declarations to the hubot module. Since the Hubot namespace is assigned as the export of the module, any augmentations made to the module will target that namespace directly; writing another namespace Hubot { ... } in the augmentation would create a nested namespace, which isn't what you want. Finally, declaring a class gives a "duplicate identifier" error, while declaring an interface is sufficient to add properties.






          share|improve this answer





















          • Thanks, worked perfectly, and thanks for the explanation. It makes sense now.
            – JCM
            2 days ago















          up vote
          3
          down vote



          accepted










          hubot.d.ts should contain:



          // This import serves no purpose except to make the file a module
          // (so that the following statement is a module augmentation rather
          // than a module declaration) and could be replaced with `export {}`.
          import * as hubot from 'hubot';

          declare module "hubot" {
          interface Message {
          mentions: string
          }
          }


          A module augmentation is needed to add declarations to the hubot module. Since the Hubot namespace is assigned as the export of the module, any augmentations made to the module will target that namespace directly; writing another namespace Hubot { ... } in the augmentation would create a nested namespace, which isn't what you want. Finally, declaring a class gives a "duplicate identifier" error, while declaring an interface is sufficient to add properties.






          share|improve this answer





















          • Thanks, worked perfectly, and thanks for the explanation. It makes sense now.
            – JCM
            2 days ago













          up vote
          3
          down vote



          accepted







          up vote
          3
          down vote



          accepted






          hubot.d.ts should contain:



          // This import serves no purpose except to make the file a module
          // (so that the following statement is a module augmentation rather
          // than a module declaration) and could be replaced with `export {}`.
          import * as hubot from 'hubot';

          declare module "hubot" {
          interface Message {
          mentions: string
          }
          }


          A module augmentation is needed to add declarations to the hubot module. Since the Hubot namespace is assigned as the export of the module, any augmentations made to the module will target that namespace directly; writing another namespace Hubot { ... } in the augmentation would create a nested namespace, which isn't what you want. Finally, declaring a class gives a "duplicate identifier" error, while declaring an interface is sufficient to add properties.






          share|improve this answer












          hubot.d.ts should contain:



          // This import serves no purpose except to make the file a module
          // (so that the following statement is a module augmentation rather
          // than a module declaration) and could be replaced with `export {}`.
          import * as hubot from 'hubot';

          declare module "hubot" {
          interface Message {
          mentions: string
          }
          }


          A module augmentation is needed to add declarations to the hubot module. Since the Hubot namespace is assigned as the export of the module, any augmentations made to the module will target that namespace directly; writing another namespace Hubot { ... } in the augmentation would create a nested namespace, which isn't what you want. Finally, declaring a class gives a "duplicate identifier" error, while declaring an interface is sufficient to add properties.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 16 at 22:01









          Matt McCutchen

          12.9k719




          12.9k719












          • Thanks, worked perfectly, and thanks for the explanation. It makes sense now.
            – JCM
            2 days ago


















          • Thanks, worked perfectly, and thanks for the explanation. It makes sense now.
            – JCM
            2 days ago
















          Thanks, worked perfectly, and thanks for the explanation. It makes sense now.
          – JCM
          2 days ago




          Thanks, worked perfectly, and thanks for the explanation. It makes sense now.
          – JCM
          2 days ago


















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53345357%2fhow-to-augment-class-declared-but-not-exported-on-typescript-module%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

          Alcedinidae

          Origin of the phrase “under your belt”?