How to import a js library without definition file in typescript file

前端 未结 5 1762
温柔的废话
温柔的废话 2020-12-01 03:23

I want to switch from JavaScript to TypeScript to help with code management as our project gets larger. We utilize, however, lots of libraries as amd Modules, which we do no

5条回答
  •  暖寄归人
    2020-12-01 03:56

    A combination of the 2 answers given here worked for me.

    //errorInfoHandler.d.ts
    declare module "lib/errorInfoHandler" {
       var noTypeInfoYet: any; // any var name here really
       export = noTypeInfoYet;
    }
    

    I'm still new to TypeScript but it looks as if this is just a way to tell TypeScript to leave off by exporting a dummy variable with no type information on it.

    EDIT

    It has been noted in the comments for this answer that you can achieve the same result by simply declaring:

    //errorInfoHandler.d.ts
    declare module "*";
    

    See the github comment here.

提交回复
热议问题