Tsickle emits bound `this` generics which trigger jscompiler whitelist conformance checks
See original GitHub issuem getting a conformance check error with a generic this value:
/**
* d3 inverts the `this` ownership. buildD3Handler reverts that, so that the
* passed method is called in the original context with the d3 value as the
* input.
*/
export function
buildD3Handler<ContextT, SVGEltT extends SVGElement, BoundObjT extends
BoundD3T, HandlerRetT>(
context: ContextT,
targetMethod: (svgElt: SVGEltT, boundObj: BoundObjT) => HandlerRetT,
): d3.ValueFn<SVGEltT, BoundObjT, HandlerRetT> {
return function(this: SVGEltT, node: BoundObjT) {
// Here 'this' is a reference to the D3 DOM Node
return targetMethod.call(context, this, node);
};
}
As far as I can tell, this is sensible:
/**
* d3 inverts the `this` ownership. buildD3Handler reverts that, so that the
* passed method is called in the original context with the d3 value as the
* input.
* @template ContextT, SVGEltT, BoundObjT, HandlerRetT
* @param {ContextT} context
* @param {function(SVGEltT, BoundObjT): HandlerRetT} targetMethod
* @return {?}
*/
function buildD3Handler(context, targetMethod) {
return (/**
* @this {SVGEltT}
* @param {BoundObjT} node
* @return {?}
*/
function (node) {
// Here 'this' is not a reference to TopologyGraphComponent object.
return targetMethod.call(context, this, node);
});
}
But I am getting:
ERROR - Violation: References to "this" that are typed as "unknown" are not allowed. See https://github.com/google/closure-compiler/wiki/Conformance:-Unknown-type-of-%E2%80%9Cthis%E2%80%9D
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:6 (4 by maintainers)
Top Results From Across the Web
Issues · angular/tsickle - GitHub
Tsickle emits bound this generics which trigger jscompiler whitelist conformance checks. #1015 opened on Apr 15, 2019 by DavidSouther.
Read more >tsickle @ 0.34.3 .. 0.35.0 - Package Diff
+Tsickle emits modules using Closure's `goog.module` module system. This system. +is similar to but different from ES modules, and was supported by Closure ......
Read more >Introduction - Build software better, together
Ignore base objects of empty types in BanSetAttribute conformance checks. We've seen false positives related to this. In some terribly typed JS code,...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I ran into this recently. Adding an explicit cast (e.g.
this as SVGEltT}
) seems to fix it.If tsickle automatically emitted the type assertion, both on static methods (because of https://github.com/google/closure-compiler/issues/3340) and when a function has an explicit
this
type it would do wonders for code legibility.If I followed the bug, this isn’t even about generic bounds really. It’s that code like
fails because you can’t use a templated type in a
this
clause. So the generic bounds thing doesn’t even help.