既存の型定義を拡張または変更する「ベスト プラクティス」の方法を探しています。
私は最近、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 の 1 つを使用したい場合は、LoDashStatic の代わりに ILoDashWithMixins を使用する必要があります。
できます。しかし、私はそれを「正しい」方法で行いたいと思っています。