/**
* @description 6-9 面试题:自定义守卫如何判断 Promise 类型
*/
function securityCheck( guest: any) {
if (isPromise(guest)) {
return guest.then((val) => {
console.log(val);
});
}
}
function isPromise( guest: any) : guest is Promise<any> {
return guest instanceof Promise;
}
securityCheck(Promise.resolve('1111'));