Export and publish all types and interfaces in Typescript

前端 未结 1 390
感情败类
感情败类 2021-01-20 02:02

I am trying to publish a typescript library. It is not clear to me how to expose all the types and interfaces. Here is my setup:

mylib
  ├──src
  │  ├──types
         


        
相关标签:
1条回答
  • 2021-01-20 02:24

    I recently faced the same problem and the only way I found in order to publish your Type-Space code (e.g.: types, interfaces) together with your Value-Space code (e.g.: function, classes, variables) is to export a namespace that contains everything.

    Another odd thing is that in order to export into a namespace something imported, the syntax is:

    import * as mymod from './mymod';
    import * as mytypes from './mytypes';
    
    export namespace mylib {
      export import mod = mymod;
      export import types = mytypes;
    }
    

    With the export import syntax.

    Unfortunately this in my eslinter will resolve in a warning/error since apparently it reads mod and types as unused-vars.

    I don't understand why there is no a full explanation for this topic in the documentation.

    0 讨论(0)
提交回复
热议问题