question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Tsickle emits bound `this` generics which trigger jscompiler whitelist conformance checks

See original GitHub issue

m 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:open
  • Created 4 years ago
  • Reactions:3
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
ricticcommented, Apr 18, 2019

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.

0reactions
evmarcommented, Sep 27, 2019

If I followed the bug, this isn’t even about generic bounds really. It’s that code like

/**
 * @template T
 */
function f() {
  /** @this {T} */
  function f2() {}
}

fails because you can’t use a templated type in a this clause. So the generic bounds thing doesn’t even help.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found