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

Improve the typings for goog.Promise. - #689

Merged
LucasSloan merged 1 commit into
masterfrom
better-goog-promise-typing
Feb 13, 2018
Merged

LucasSloan merged 1 commit into
masterfrom
better-goog-promise-typing

Conversation

@LucasSloan

Copy link
Copy Markdown
Contributor

Clutz hard codes translations for TTE types, and goog.Promise has 2 type parameters, which wasn't previously accounted for in the translations.

Had to turn on noStrictGenericChecks to make it compile, ts doesn't like extending promise-y things.

@LucasSloan
LucasSloan requested a review from rkirov February 13, 2018 00:33
@LucasSloan
LucasSloan force-pushed the better-goog-promise-typing branch from 8e7cab3 to 6acf839 Compare February 13, 2018 00:49
@@ -0,0 +1,131 @@
//!! goog.Promise, unlike other implementations of Promise, has 2 template params
//!! this test ensures that the specially handled TTE methods work for it as well

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

closure libs are on github - add a reference here for that.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

// TODO(lucassloan): goog.Promise has bad types that are coerced to any, so explicitly emit any
// and fix when the callers have been fixed.
if (className.equals("ಠ_ಠ.clutz.goog.Promise")) {
return "resolve < T >(value: " + className + " < T , any > | T): any;";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

OOC, what happens if you do : <T, any> for the return type too?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That's the correct type, and all the bad user's code is surfaced.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I see, expand the comment so it is even clear what is the future state here - the correct type here would be (value: googPromise< T , any > | T): googPromise<T, any>;

String templateVarName = templateTypeNames.next();

String classTemplatizedType = className + " < RESULT >";
// TODO(lucassloan): goog.Promise has bad types that are coerced to any, so explicitly emit any

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

expand 'bad types' -> because of change from 1 type param to 2.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

"--noImplicitAny",
"--strictNullChecks");
"--strictNullChecks",
"--noStrictGenericChecks");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

add a comment next to this flag, similar to the one in the cl description. Long-term we should attempt removing this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

class PartialDeferred_Instance < VALUE = any > extends ಠ_ಠ.clutz.Base < VALUE > {
constructor ( ) ;
then < RESULT > (opt_onFulfilled ? : ( (a : VALUE ) => PartialDeferred < RESULT > | RESULT ) | null , opt_onRejected ? : ( (a : any ) => any ) | null) : PartialDeferred < RESULT > ;
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 > ;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this looks wrong? where is ಠ_ಠ.clutz.module$exports$tte$Promise$Partial defined?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Right here. PartialDefered_Instance is extended by PartialDeferred, which are both in the ಠ_ಠ.clutz.module$exports$tte$Promise$Partial namespace.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I see, I guess I expected PartialDeferred but doesn't hurt to fully qualify.

// TODO(lucassloan): goog.Promise has bad types that are coerced to any, so explicitly emit any
// and fix when the callers have been fixed.
String classTemplatizedType =
className.equals("ಠ_ಠ.clutz.goog.Promise") ? " any" : className + " < RESULT >";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

unless I am missing something, there is no test for users of 'goog.Promise' only tests for the declaration?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Correct.

@LucasSloan LucasSloan left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

PTAL

String templateVarName = templateTypeNames.next();

String classTemplatizedType = className + " < RESULT >";
// TODO(lucassloan): goog.Promise has bad types that are coerced to any, so explicitly emit any

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

// TODO(lucassloan): goog.Promise has bad types that are coerced to any, so explicitly emit any
// and fix when the callers have been fixed.
String classTemplatizedType =
className.equals("ಠ_ಠ.clutz.goog.Promise") ? " any" : className + " < RESULT >";

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Correct.

// TODO(lucassloan): goog.Promise has bad types that are coerced to any, so explicitly emit any
// and fix when the callers have been fixed.
if (className.equals("ಠ_ಠ.clutz.goog.Promise")) {
return "resolve < T >(value: " + className + " < T , any > | T): any;";

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That's the correct type, and all the bad user's code is surfaced.

"--noImplicitAny",
"--strictNullChecks");
"--strictNullChecks",
"--noStrictGenericChecks");

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

@@ -0,0 +1,131 @@
//!! goog.Promise, unlike other implementations of Promise, has 2 template params
//!! this test ensures that the specially handled TTE methods work for it as well

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

class PartialDeferred_Instance < VALUE = any > extends ಠ_ಠ.clutz.Base < VALUE > {
constructor ( ) ;
then < RESULT > (opt_onFulfilled ? : ( (a : VALUE ) => PartialDeferred < RESULT > | RESULT ) | null , opt_onRejected ? : ( (a : any ) => any ) | null) : PartialDeferred < RESULT > ;
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 > ;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Right here. PartialDefered_Instance is extended by PartialDeferred, which are both in the ಠ_ಠ.clutz.module$exports$tte$Promise$Partial namespace.

@rkirov rkirov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Open a clutz bug to track this too

// TODO(lucassloan): goog.Promise has bad types that are coerced to any, so explicitly emit any
// and fix when the callers have been fixed.
if (className.equals("ಠ_ಠ.clutz.goog.Promise")) {
return "resolve < T >(value: " + className + " < T , any > | T): any;";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I see, expand the comment so it is even clear what is the future state here - the correct type here would be (value: googPromise< T , any > | T): googPromise<T, any>;

class PartialDeferred_Instance < VALUE = any > extends ಠ_ಠ.clutz.Base < VALUE > {
constructor ( ) ;
then < RESULT > (opt_onFulfilled ? : ( (a : VALUE ) => PartialDeferred < RESULT > | RESULT ) | null , opt_onRejected ? : ( (a : any ) => any ) | null) : PartialDeferred < RESULT > ;
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 > ;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I see, I guess I expected PartialDeferred but doesn't hurt to fully qualify.

Clutz hard codes translations for TTE types, and goog.Promise has 2 type parameters, which wasn't previously accounted for in the translations.

Had to turn on noStrictGenericChecks to make it compile, ts doesn't like extending promise-y things.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants