1

我正在寻找一种扩展或更改现有类型定义的“最佳实践”方式。

我最近发现有一种这样的“最佳实践”可以扩展 lib.d.ts。它被称为 globals.d.ts。 https://basarat.gitbooks.io/typescript/content/docs/project/globals.html

但是,据我所知,该文件仅用于扩展 lib.d.ts。

所以我的问题是。扩展例如 lodash.d.ts 的“最佳实践”是什么?

目前我只有一个my-project.ts在根文件夹中

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>;
    }
}

这样做需要我使用自己的接口。因此,当我想使用我的一个 lodash mixin 时,我必须使用 ILoDashWithMixins 而不是 LoDashStatic。

有用。但我想以“正确”的方式来做。

4

0 回答 0