Make resolve and reject values optional in the TypeScript definition (#3)

This commit is contained in:
Dave Gramlich 2019-03-23 01:53:14 -07:00 committed by Sindre Sorhus
parent 897315f950
commit f84a36653e
2 changed files with 4 additions and 2 deletions

4
index.d.ts vendored
View File

@ -4,14 +4,14 @@ export interface DeferredPromise<ValueType> {
@param value - The value to resolve the promise with.
*/
resolve(value: ValueType | PromiseLike<ValueType>): void;
resolve(value?: ValueType | PromiseLike<ValueType>): void;
/**
Reject the promise with a provided reason or error.
@param reason - The reason or error to reject the promise with.
*/
reject(reason: unknown): void;
reject(reason?: unknown): void;
/**
The deferred promise.

View File

@ -4,6 +4,8 @@ import pDefer, {DeferredPromise} from '.';
expectType<DeferredPromise<unknown>>(pDefer());
expectType<DeferredPromise<string>>(pDefer<string>());
pDefer<void>().resolve();
pDefer<string>().resolve('foo');
pDefer<void>().reject();
pDefer<string>().reject(new Error('foo'));
expectType<Promise<string>>(pDefer<string>().promise);