mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
Add typings for the promise-hash library, v1.3 (#40331)
* Added typings for this promise-hash library * pull out common type for the promise hash argument * make recommended simplifications, expand test
This commit is contained in:
parent
b692892009
commit
6061d28041
16
types/promise-hash/index.d.ts
vendored
Normal file
16
types/promise-hash/index.d.ts
vendored
Normal file
@ -0,0 +1,16 @@
|
||||
// Type definitions for promise-hash 1.3
|
||||
// Project: https://github.com/mtimofiiv/promise-hash
|
||||
// Definitions by: Michael Shafir <https://github.com/mshafir>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
export = hash;
|
||||
|
||||
type PromiseHash = <T>(promiseHash: { [P in keyof T]: PromiseLike<T[P]> | T[P] }) => Promise<T>;
|
||||
|
||||
declare global {
|
||||
interface PromiseConstructor {
|
||||
hash: PromiseHash;
|
||||
}
|
||||
}
|
||||
|
||||
declare const hash: PromiseHash;
|
||||
23
types/promise-hash/promise-hash-tests.ts
Normal file
23
types/promise-hash/promise-hash-tests.ts
Normal file
@ -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<boolean>
|
||||
|
||||
const result2 = hash({
|
||||
test: Promise.resolve("hello world")
|
||||
});
|
||||
|
||||
result2; // $ExpectType Promise<{ test: string; }>
|
||||
23
types/promise-hash/tsconfig.json
Normal file
23
types/promise-hash/tsconfig.json
Normal file
@ -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"
|
||||
]
|
||||
}
|
||||
1
types/promise-hash/tslint.json
Normal file
1
types/promise-hash/tslint.json
Normal file
@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Loading…
Reference in New Issue
Block a user