1

I'm looking for a "best practice" way of extending or altering an existing type-definition.

I recently found out that there is one such "best practice" for extending lib.d.ts. It's called globals.d.ts. https://basarat.gitbooks.io/typescript/content/docs/project/globals.html

But, as far as I can tell, that file is only meant for extending lib.d.ts.

So my question is. What is the "best practice" for extending for example lodash.d.ts?

Currently I just have a my-project.ts in the root folder

module MyProject {
    export interface ILoDashWithMixins extends _.LoDashStatic {
        deep(obj, key, value?);
        pluckDeep(obj, key);
        unpick(obj);
        resursivePluck(obj, key, childPropertyName?);
        findKeyDeep(obj, keyObj);
    }

    export interface IRequestShortcutConfigWithCustomConfig extends ng.IRequestShortcutConfig {
        [key: string]: any;
    }

    export interface IHttpServiceWithCustomConfig extends ng.IHttpService {
        post<T>(url: string, data: any, config?: IRequestShortcutConfigWithCustomConfig): ng.IHttpPromise<T>;
    }
}

Doing it this way requires me to use my own interfaces. So when I want to use one of my lodash mixins I have to use ILoDashWithMixins instead of LoDashStatic.

It works. But I want to do it the "correct" way.

Snæbjørn
  • 10,322
  • 14
  • 65
  • 124

0 Answers0