Repository navigation
Improve the typings for goog.Promise. - #689
Conversation
8e7cab3 to
6acf839
Compare
| @@ -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 | |||
There was a problem hiding this comment.
closure libs are on github - add a reference here for that.
| // 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;"; |
There was a problem hiding this comment.
OOC, what happens if you do : <T, any> for the return type too?
There was a problem hiding this comment.
That's the correct type, and all the bad user's code is surfaced.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
expand 'bad types' -> because of change from 1 type param to 2.
| "--noImplicitAny", | ||
| "--strictNullChecks"); | ||
| "--strictNullChecks", | ||
| "--noStrictGenericChecks"); |
There was a problem hiding this comment.
add a comment next to this flag, similar to the one in the cl description. Long-term we should attempt removing this.
| 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 > ; |
There was a problem hiding this comment.
this looks wrong? where is ಠ_ಠ.clutz.module$exports$tte$Promise$Partial defined?
There was a problem hiding this comment.
Right here. PartialDefered_Instance is extended by PartialDeferred, which are both in the ಠ_ಠ.clutz.module$exports$tte$Promise$Partial namespace.
There was a problem hiding this comment.
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 >"; |
There was a problem hiding this comment.
unless I am missing something, there is no test for users of 'goog.Promise' only tests for the declaration?
| String templateVarName = templateTypeNames.next(); | ||
|
|
||
| String classTemplatizedType = className + " < RESULT >"; | ||
| // TODO(lucassloan): goog.Promise has bad types that are coerced to any, so explicitly emit any |
| // 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 >"; |
| // 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;"; |
There was a problem hiding this comment.
That's the correct type, and all the bad user's code is surfaced.
| "--noImplicitAny", | ||
| "--strictNullChecks"); | ||
| "--strictNullChecks", | ||
| "--noStrictGenericChecks"); |
| @@ -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 | |||
| 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 > ; |
There was a problem hiding this comment.
Right here. PartialDefered_Instance is extended by PartialDeferred, which are both in the ಠ_ಠ.clutz.module$exports$tte$Promise$Partial namespace.
rkirov
left a comment
There was a problem hiding this comment.
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;"; |
There was a problem hiding this comment.
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 > ; |
There was a problem hiding this comment.
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.
b39f93e to
2ba0534
Compare
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.