5

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?

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the confirmation - I was wondering why others didn't follow this approach which made me concerned I was erring from the true path. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.