Namespaces for interfaces in typescript definition file

Qua*_*ngo 5 namespaces typescript

I am writing a TypeScript definition file (.d.ts) for a JS library that doesn't currently have one.

Other .d.ts file seem to put all the types into the 'global' namespace (if you see what I mean), whereas I am trying do the following:

// root valerie object 
//
declare var valerie: Valerie.ValerieStatic;

// additional types for Valerie (all inside this virtual namespace)

declare module Valerie {

    //
    // Static methods on valerie namespace
    //
    interface ValerieStatic {
        // definitions go here.....
Run Code Online (Sandbox Code Playgroud)

This means that I don't potentially get my interfaces crossed with others should they exist.

My question is - it seems to work, but is there a possible problem with this approach?

Rya*_*ugh 2

一般来说,这是一个很好的方法。如果模块内有一些Valerie您希望人们经常使用的接口类型,您可能会考虑将它们提升到顶级,以便更方便地引用它们。