Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Namespaces for interfaces in typescript definition file

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.....

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?

like image 866
Quango Avatar asked Nov 02 '22 12:11

Quango


1 Answers

In general this is a good approach. If there are some interface types inside the Valerie module that you would expect people to be using often, you might consider promoting them to top-level so it's more convenient to reference them.

like image 174
Ryan Cavanaugh Avatar answered Nov 08 '22 08:11

Ryan Cavanaugh