私はasync
ライブラリの*-as-promised
versionをタイプスクリプトで、@types/async
タイプを再利用しようとしています。TypeScriptで別々の関数宣言をマージするには?
export function filter<T, E>(arr: T[] | IterableIterator<T>, iterator: AsyncBooleanIterator<T, E>, callback?: AsyncResultArrayCallback<T, E>): void;
export function filter<T, E>(arr: Dictionary<T>, iterator: AsyncBooleanIterator<T, E>, callback?: AsyncResultArrayCallback<T, E>): void;
しかし、私にonly export one .filter function:
:function filter<T>(
arr: async.Dictionary<T> | T[] | IterableIterator<T>,
iterator: (item: T) => Promise<boolean>
): Promise<Array<(T | undefined)> | undefined> {
return new Promise((resolve, reject) => {
async.filter(arr, (item, cb) => {
iterator(item)
.then(res => cb(undefined, res))
.catch(err => cb(err));
}, (err, results) =>
err
? reject(err)
: resolve(results)
);
});
}
コンパイル、これは私に次のエラーを与える
私の問題は@types/async at the .filter functionが同じ名前を持つ2つの機能の種類をエクスポートしているということです
lib/filter.ts(32,18): error TS2345: Argument of type 'Dictionary<T> | IterableIterator<T> | T[]' is not assignable to parameter of type 'Dictionary<T>'.
Type 'IterableIterator<T>' is not assignable to type 'Dictionary<T>'.
だから、どのように私はこれらの宣言をただ一つにマージできますか?
ありがとう。
私はその解決策、おかげで行く@jcalz! –