How do I write a TypeScript declaration file for a complex external commonjs module that has constructor, such as imap?

前端 未结 2 1872
一向
一向 2021-01-25 12:09

This question is a refinement of my earlier one: How do I write a TypeScript declaration file for an external commonjs module that has constructor?

I\'m trying to write

2条回答
  •  长发绾君心
    2021-01-25 12:39

    Ideally, all of the interfaces will be defined inside of module "imap", so there is no pollution of the global scope

    Instead of:

    interface IFetchOptions {
        markSeen:       boolean;
        // so on
    }
    interface ICriteria {        
        ALL:            void;
    }
    

    Do the following

    module imap {
        interface IFetchOptions {
            markSeen:       boolean;
            // so on
        }
        interface ICriteria {        
            ALL:            void;
        }
    }
    

    And you only pollute the global scope with imap. Which is a non-initializaed module and can only be used for Type Information.

    Reference : look at ghost modules : http://definitelytyped.org/guides/best-practices.html

提交回复
热议问题