diff --git a/types/promise-hash/index.d.ts b/types/promise-hash/index.d.ts new file mode 100644 index 0000000000..02d3feba2d --- /dev/null +++ b/types/promise-hash/index.d.ts @@ -0,0 +1,16 @@ +// Type definitions for promise-hash 1.3 +// Project: https://github.com/mtimofiiv/promise-hash +// Definitions by: Michael Shafir +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +export = hash; + +type PromiseHash = (promiseHash: { [P in keyof T]: PromiseLike | T[P] }) => Promise; + +declare global { + interface PromiseConstructor { + hash: PromiseHash; + } +} + +declare const hash: PromiseHash; diff --git a/types/promise-hash/promise-hash-tests.ts b/types/promise-hash/promise-hash-tests.ts new file mode 100644 index 0000000000..affe35992b --- /dev/null +++ b/types/promise-hash/promise-hash-tests.ts @@ -0,0 +1,23 @@ +import hash = require('promise-hash'); + +const result = Promise.hash({ + a: 5, + b: Promise.resolve("test"), + c: Promise.hash({ + d: Promise.resolve(true), + e: Promise.resolve("again") + }) +}); + +type expectedType = Promise<{ a: number; b: string; c: { d: boolean; e: string; } }>; +type resultIsExpected = typeof result extends expectedType ? true : false; // $ExpectType true +type expectedIsResult = expectedType extends typeof result ? true : false; // $ExpectType true + +const dResult = result.then(x => x.c.d); +dResult; // $ExpectType Promise + +const result2 = hash({ + test: Promise.resolve("hello world") +}); + +result2; // $ExpectType Promise<{ test: string; }> diff --git a/types/promise-hash/tsconfig.json b/types/promise-hash/tsconfig.json new file mode 100644 index 0000000000..c3e76c0ffd --- /dev/null +++ b/types/promise-hash/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "promise-hash-tests.ts" + ] +} \ No newline at end of file diff --git a/types/promise-hash/tslint.json b/types/promise-hash/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/promise-hash/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }