[retry-as-promised] add type definitions

This commit is contained in:
Florian Oellerich 2018-02-14 17:16:18 +01:00
parent 8ceee56cb9
commit fb0f3f789f
4 changed files with 81 additions and 0 deletions

27
types/retry-as-promised/index.d.ts vendored Normal file
View File

@ -0,0 +1,27 @@
// Type definitions for retry-as-promised 2.3
// Project: https://github.com/mickhansen/retry-as-promised
// Definitions by: Florian Oellerich <https://github.com/Raigen>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
import Promise = require('bluebird');
declare namespace retryAsPromised {
type MatchOption = string | RegExp | Error;
interface Options {
$current?: number;
max?: number;
timeout?: number;
match?: MatchOption[] | MatchOption;
backoffBase?: number;
backoffExponent?: number;
report?: (message: string, obj: Options, err?: any) => void;
name?: string;
}
type RetryCallback<T> = ({ current }: { current: Options['$current'] }) => Promise.Thenable<T>;
type RetryAsPromisedStatic = <T = any>(callback: RetryCallback<T>, options: Options | number) => Promise<T>;
}
declare const retryAsPromised: retryAsPromised.RetryAsPromisedStatic;
export = retryAsPromised;

View File

@ -0,0 +1,27 @@
import retry = require('retry-as-promised');
interface Product {
name: string;
}
const log = (...args: any[]): void => {};
retry(() => Promise.resolve(), {});
retry(() => Promise.reject('Error matching values'), {});
retry(() => Promise.reject(new Error('No matching values')), {});
retry(() => Promise.resolve(), {
max: 100,
timeout: 60000,
match: ['Error matching values', new Error('No matching values'), new RegExp(/Deadlock/, 'i')],
backoffBase: 100,
backoffExponent: 1.1,
name: 'Source',
report: (message, options) => {
if (options.name === 'Source') {
log(options.name);
log('iteration', options.$current);
}
}
});
retry<Product>(() => Promise.resolve({ name: 'test' }) , {});
retry<Product>(() => Promise.reject(new Error('No matching product')), {});

View File

@ -0,0 +1,24 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true,
"esModuleInterop": true,
"strictFunctionTypes": true
},
"files": [
"index.d.ts",
"retry-as-promised-tests.ts"
]
}

View File

@ -0,0 +1,3 @@
{
"extends": "dtslint/dt.json"
}