mirror of
https://github.com/chenasraf/DefinitelyTyped.git
synced 2026-05-18 01:49:01 +00:00
🤖 Merge PR #49807 update(pify): v5 update by @peterblazejewicz
This updates to version 5 and while doing so, as the update has no breaking API changes, make some cleanup and simplification in the module definition, so it's easier to maintain: - linter simplification - DT header rewrite with proper versioning, etc - tests amended - version bump https://github.com/sindresorhus/pify/compare/v3.0.0...v5.0.0 Thanks!
This commit is contained in:
committed by
GitHub
parent
5d2ecf70ab
commit
ae50eb9ce3
39
types/pify/index.d.ts
vendored
39
types/pify/index.d.ts
vendored
@@ -1,23 +1,28 @@
|
||||
// Type definitions for pify 3.0.0
|
||||
// Type definitions for pify 5.0
|
||||
// Project: https://github.com/sindresorhus/pify
|
||||
// Definitions by: Sam Verschueren <https://github.com/samverschueren>, [Michael Müller] <https://github.com/mad-mike>, Christoph Müller <https://github.com/c7hm4r>
|
||||
// Definitions by: Sam Verschueren <https://github.com/samverschueren>
|
||||
// Michael Müller <https://github.com/mad-mike>
|
||||
// Christoph Müller <https://github.com/c7hm4r>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
interface PromiseModule {
|
||||
new(executor: (resolve: (value?: any) => void, reject: (reason?: any) => void) => void): any;
|
||||
type InputFunction = (...args: any[]) => any;
|
||||
|
||||
declare function pify(input: InputFunction, options?: pify.PifyOptions): (...args: any[]) => Promise<any>;
|
||||
declare function pify(input: object, options?: pify.PifyOptions): any;
|
||||
|
||||
declare namespace pify {
|
||||
interface PifyOptions {
|
||||
multiArgs?: boolean;
|
||||
include?: Array<string | RegExp>;
|
||||
exclude?: Array<string | RegExp>;
|
||||
excludeMain?: boolean;
|
||||
errorFirst?: boolean;
|
||||
promiseModule?: PromiseModule;
|
||||
}
|
||||
|
||||
interface PromiseModule {
|
||||
new (executor: (resolve: (value?: any) => void, reject: (reason?: any) => void) => void): any;
|
||||
}
|
||||
}
|
||||
|
||||
interface PifyOptions {
|
||||
multiArgs?: boolean,
|
||||
include?: Array<string | RegExp>,
|
||||
exclude?: Array<string | RegExp>,
|
||||
excludeMain?: boolean,
|
||||
errorFirst?: boolean,
|
||||
promiseModule?: PromiseModule
|
||||
}
|
||||
|
||||
declare function pify(input: Function, options?: PifyOptions): (...args: any[]) => Promise<any>;
|
||||
declare function pify(input: any, options?: PifyOptions): any;
|
||||
|
||||
declare namespace pify { }
|
||||
export = pify;
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import pify = require('pify');
|
||||
|
||||
type CallbackFunction = (...args: any[]) => any;
|
||||
|
||||
function assert(actual: string, expected: string): void {
|
||||
if (actual !== expected) {
|
||||
throw new Error(`${JSON.stringify(actual)} !== ${JSON.stringify(expected)}`);
|
||||
@@ -7,8 +9,8 @@ function assert(actual: string, expected: string): void {
|
||||
}
|
||||
|
||||
const fs = {
|
||||
readFile: (file: string, callback: Function) => {
|
||||
let result: any = undefined;
|
||||
readFile: (file: string, callback: CallbackFunction) => {
|
||||
let result;
|
||||
|
||||
if (file === 'foo.txt') {
|
||||
result = 'foo';
|
||||
@@ -20,7 +22,7 @@ const fs = {
|
||||
},
|
||||
exists: (path: string, callback: (exists: boolean) => void): void => {
|
||||
callback(true);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
const fsP = pify(fs);
|
||||
@@ -29,14 +31,13 @@ fsP.readFile('foo.txt').then((result: string) => assert(result, 'foo'));
|
||||
pify(fs.readFile)('foo.txt').then((result: string) => assert(result, 'foo'));
|
||||
pify(fs.readFile, { promiseModule: Promise })('bar.txt').then((result: string) => assert(result, 'bar'));
|
||||
|
||||
|
||||
pify(fs.exists, { errorFirst: false })('foo.txt').then((result: boolean) => assert(result.toString(), true.toString()));
|
||||
|
||||
// include/exclude with multiple entries
|
||||
const module = {
|
||||
f1: (callback: Function) => callback(),
|
||||
f2: (callback: Function) => callback(),
|
||||
f3: (callback: Function) => callback(),
|
||||
f1: (callback: CallbackFunction) => callback(),
|
||||
f2: (callback: CallbackFunction) => callback(),
|
||||
f3: (callback: CallbackFunction) => callback(),
|
||||
};
|
||||
|
||||
const include = pify(module, { include: ['f1', 'f2'] });
|
||||
@@ -48,3 +49,8 @@ const exclude = pify(module, { exclude: ['f1', 'f2'] });
|
||||
if (exclude.f1 !== module.f1) throw new Error();
|
||||
if (exclude.f2 !== module.f2) throw new Error();
|
||||
if (exclude.f3 === module.f3) throw new Error();
|
||||
|
||||
(async () => {
|
||||
const data = await pify(fs.readFile)('package.json', 'utf8');
|
||||
const data2 = await pify(fs).readFile('package.json', 'utf8');
|
||||
})();
|
||||
|
||||
@@ -1,10 +1,3 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json",
|
||||
"rules": {
|
||||
"ban-types": false,
|
||||
"dt-header": false,
|
||||
"no-consecutive-blank-lines": false,
|
||||
"no-unnecessary-initializer": false,
|
||||
"semicolon": false
|
||||
}
|
||||
"extends": "dtslint/dt.json"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user