feat(core): add `isPromise` generic (#34168)

This commit adds generic to `isPromise` function to help with type inference.

PR Close #34168
This commit is contained in:
danranVm 2020-03-18 15:28:25 +08:00 committed by Misko Hevery
parent b4972fa165
commit 47bfec4e46
3 changed files with 3 additions and 3 deletions

View File

@ -31,7 +31,7 @@ export function isAnchor(el: (Node & ParentNode) | Element | null): el is HTMLAn
return (<HTMLAnchorElement>el).href !== undefined;
}
export function isPromise(obj: any): obj is Promise<any> {
export function isPromise<T = any>(obj: any): obj is Promise<T> {
// allow any Promise/A+ compliant thenable.
// It's up to the caller to ensure that obj.then conforms to the spec
return !!obj && typeof obj.then === 'function';

View File

@ -214,7 +214,7 @@ export function resolveForwardRef(type: any): any {
/**
* Determine if the argument is shaped like a Promise
*/
export function isPromise(obj: any): obj is Promise<any> {
export function isPromise<T = any>(obj: any): obj is Promise<T> {
// allow any Promise/A+ compliant thenable.
// It's up to the caller to ensure that obj.then conforms to the spec
return !!obj && typeof obj.then === 'function';

View File

@ -11,7 +11,7 @@ import {Observable} from 'rxjs';
/**
* Determine if the argument is shaped like a Promise
*/
export function isPromise(obj: any): obj is Promise<any> {
export function isPromise<T = any>(obj: any): obj is Promise<T> {
// allow any Promise/A+ compliant thenable.
// It's up to the caller to ensure that obj.then conforms to the spec
return !!obj && typeof obj.then === 'function';