-
Notifications
You must be signed in to change notification settings - Fork 60
Return types on Promise #806
Comments
#689 introduced the type definition.
I don't know why it has to return declare namespace ಠ_ಠ.clutz.goog {
class Promise < TYPE , RESOLVER_CONTEXT = void > implements ಠ_ಠ.clutz.goog.Thenable < TYPE > {
constructor (resolver : (this : RESOLVER_CONTEXT , a : (a ? : TYPE | PromiseLike < TYPE > | null | { then : any } ) => any , b : (a ? : any ) => any ) => void , opt_context ? : RESOLVER_CONTEXT ) ;
then < RESULT > (opt_onFulfilled ? : ( (a : TYPE ) => PromiseLike < RESULT > | RESULT ) | null , opt_onRejected ? : ( (a : any ) => any ) | null) : ಠ_ಠ.clutz.goog.Promise < RESULT > ;
static resolve < T > (value : PromiseLike < T > | T ): ಠ_ಠ.clutz.goog.Promise < T > ;
}
} @rkirov @LucasSloan How about this? Can I send PR to fix it? |
The externs for |
@teppeis Thanks for looking into this. Yes, the comment refers to google internal code, which is the primary consumer of clutz generated .d.ts files. Having 'any's was a temporary solution as we were working through getting Unfortunately, each improvement has to be weighted against how much current violations we have in our giant codebase and how much work it is to roll it out. Always feel free to send me a PR and I will do that evaluation and let you know. Sometimes the answer would be that it would be prohibitively hard. I just did that for #830 and I can tell you that it is fine. Likely changing the return from ':any' to a proper type would not be, but again if you send me a PR I would follow up with describing common failure patterns. Often people forget that in real world codebases, users can mix up to 4 types of promises:
They are mostly runtime compatible (at least uses expect them to), so any change that makes them type-checking incompatible runs afoul of lots of existing code. |
Some of the methods on Promise have
any
as their return type. Notably,Promise.prototype.then()
andPromise.resolve()
.For example:
I'd have expected this to be
The text was updated successfully, but these errors were encountered: