mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-24 05:06:02 +08:00
* [p-lazy] introduce typings * [p-lazy] remove unnecessary TypeScript version restriction * [p-lazy] add test for reject ctor param
24 lines
494 B
TypeScript
24 lines
494 B
TypeScript
import PLazy = require('p-lazy');
|
|
|
|
const lazyPromise = new PLazy<string>((resolve, reject) => {
|
|
if (typeof resolve === 'object') {
|
|
resolve('foo');
|
|
} else {
|
|
reject(new Error());
|
|
}
|
|
});
|
|
|
|
let str: string;
|
|
|
|
lazyPromise.then(result => str = result);
|
|
|
|
Promise.resolve()
|
|
.then(() => lazyPromise)
|
|
.then(value => str = value);
|
|
|
|
let num: number;
|
|
PLazy.from(() => Promise.resolve(1))
|
|
.then(value => num = value);
|
|
PLazy.from(() => 1)
|
|
.then(value => num = value);
|