Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Improve Promise and remove --noStrictGenericChecks #830

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2968,9 +2968,7 @@ private String getSignatureForInstanceTTEFn(
} else {
return "then < RESULT > (opt_onFulfilled ? : ( (a : "
+ templateVarName
+ " ) => "
+ classTemplatizedType
+ " | RESULT ) | null , "
+ " ) => PromiseLike < RESULT > | RESULT ) | null , "
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a clever solution. In the past we just expected all promise implementations to be structurally compatible, so one can say they expect then((...): ಠ_ಠ.clutz.goog.Thenable<T>, ...) and expected that ಠ_ಠ.clutz.goog.Thenable<T> is mutually assignable with PromiseLike<T>.

However, we ran into issues when strictGenericChecks was on - the two types were not mutually assignable. That's why is is off here and we have it off in the google codebase. I think with your change the types are getting more obviously assignable, so this might no longer be an issue.

+ "opt_onRejected ? : ( (a : any ) => any ) | null) : "
+ classTemplatizedType
+ " ;";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,7 @@ public class DeclarationSyntaxTest {
"--lib",
"es5,dom,es2015.iterable",
"--noImplicitAny",
"--strictNullChecks",
// TODO(lucassloan): Necessary to allow promise like things that extend other promise like
// things. Turn off when turned off in g3
"--noStrictGenericChecks");
"--strictNullChecks");

@Test
public void testDeclarationSyntax() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ declare namespace ಠ_ಠ.clutz.goog {
class Promise < TYPE , RESOLVER_CONTEXT > implements ಠ_ಠ.clutz.goog.Thenable < TYPE > {
private noStructuralTyping_goog_Promise : any;
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 ) => any | RESULT ) | null , opt_onRejected ? : ( (a : any ) => any ) | null) : any ;
then < RESULT > (opt_onFulfilled ? : ( (a : TYPE ) => PromiseLike < RESULT > | RESULT ) | null , opt_onRejected ? : ( (a : any ) => any ) | null) : any ;
static all < TYPE > (promises : any [] ) : ಠ_ಠ.clutz.goog.Promise < TYPE [] , any > ;
static race < TYPE > (promises : any [] ) : ಠ_ಠ.clutz.goog.Promise < TYPE , any > ;
static resolve < T >(value: ಠ_ಠ.clutz.goog.Promise < T , any > | T): any;
Expand All @@ -19,7 +19,7 @@ declare namespace ಠ_ಠ.clutz.goog {
function isImplementedBy (object : any ) : boolean ;
}
interface Thenable < TYPE > extends PromiseLike < TYPE > {
then < RESULT > (opt_onFulfilled ? : ( (a : TYPE ) => ಠ_ಠ.clutz.goog.Thenable < RESULT > | RESULT ) | null , opt_onRejected ? : ( (a : any ) => any ) | null) : ಠ_ಠ.clutz.goog.Thenable < RESULT > ;
then < RESULT > (opt_onFulfilled ? : ( (a : TYPE ) => PromiseLike < RESULT > | RESULT ) | null , opt_onRejected ? : ( (a : any ) => any ) | null) : ಠ_ಠ.clutz.goog.Thenable < RESULT > ;
}
}
declare module 'goog:goog.Thenable' {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ declare namespace ಠ_ಠ.clutz.module$exports$tte$Promise$Partial {
class PartialDeferred < VALUE = any > extends ಠ_ಠ.clutz.Base < VALUE > {
private noStructuralTyping_module$exports$tte$Promise$Partial_PartialDeferred : any;
constructor ( ) ;
then < RESULT > (opt_onFulfilled ? : ( (a : VALUE ) => ಠ_ಠ.clutz.module$exports$tte$Promise$Partial.PartialDeferred < RESULT > | RESULT ) | null , opt_onRejected ? : ( (a : any ) => any ) | null) : ಠ_ಠ.clutz.module$exports$tte$Promise$Partial.PartialDeferred < RESULT > ;
then < RESULT > (opt_onFulfilled ? : ( (a : VALUE ) => PromiseLike < RESULT > | RESULT ) | null , opt_onRejected ? : ( (a : any ) => any ) | null) : ಠ_ಠ.clutz.module$exports$tte$Promise$Partial.PartialDeferred < RESULT > ;
}
}
declare module 'goog:tte.Promise.Partial' {
Expand Down