mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
31 lines
845 B
TypeScript
31 lines
845 B
TypeScript
|
|
/// <reference types="bluebird" />
|
|
|
|
import * as pify from 'pify';
|
|
import * as Bluebird from 'bluebird';
|
|
|
|
function assert(actual: string, expected: string): void {
|
|
if (actual !== expected) {
|
|
throw new Error(`${JSON.stringify(actual)} !== ${JSON.stringify(expected)}`);
|
|
}
|
|
}
|
|
|
|
const fs = {
|
|
readFile: (file: string, callback: Function) => {
|
|
let result: any = undefined;
|
|
|
|
if (file === 'foo.txt') {
|
|
result = 'foo';
|
|
} else if (file === 'bar.txt') {
|
|
result = 'bar';
|
|
}
|
|
|
|
callback(undefined, result);
|
|
}
|
|
};
|
|
|
|
const fsP = pify(fs);
|
|
fsP.readFile('foo.txt').then((result: string) => assert(result, 'foo'));
|
|
|
|
pify(fs.readFile)('foo.txt').then((result: string) => assert(result, 'foo'));
|
|
pify(fs.readFile, Bluebird)('bar.txt').then((result: string) => assert(result, 'bar')); |