TypeScript signature of Promise#catch onrejected handler -
i notice standard typing promise#catch in es6-shim.d.ts defined as
interface promise<t> { catch(onrejected?: (reason: any) => t | promiselike<t>): promise<t>; catch(onrejected?: (reason: any) => void): promise<t>; } i wondering why written way, instead of as
catch(onrejected?: (reason: any) => t | promiselike<t> | void): promise<t>; some other file es6-promise.d.ts nate archibald gives single signature of
catch<u>(onrejected?: (error: any) => u | thenable<u>): promise<u>; not referring <t> @ all.
so second overloaded signature in es6.shim-d-ts, far know in heavy use in compile-to-es5 environment, unnecessary/undesirable?
well, t can void means use case supported.
if did t | promiselike<t> | void output might have been promise<string> that's resolved void type error.
note promises aren't statically typed in strong way in these definitions. signature harder since reason typed any. languages (like c#) sport unchecked exceptions , unlike java , swift feature checked exceptions (a part of signature of function might throw).
Comments
Post a Comment