Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ugly type assertions for this #659

Merged
merged 4 commits into from
Apr 18, 2019
Merged

Add ugly type assertions for this #659

merged 4 commits into from
Apr 18, 2019

Conversation

rictic
Copy link
Contributor

@rictic rictic commented Apr 18, 2019

Because of google/closure-compiler#3340this has an unknown type to closure compiler in static methods. In order to be compatible with the Closure Compiler + JSConformance BanUnknownThis check, we must explicitly add type annotations wherever we access this in a static method.

Yes, this is pretty awful from a legibility perspective. We could improve legibility at the cost of additional size by doing:

const self = this as typeof LitElement;

I went with the zero-size-cost option here.

rictic added 3 commits April 18, 2019 14:46
Because of google/closure-compiler#3340 – `this` has an unknown type to closure compiler in static methods. In order to be compatible with the Closure Compiler + JSConformance `BanUnknownThis` check, we must explicitly add type annotations wherever we access `this` in a static method.

Yes, this is pretty awful from a legibility perspective. We could improve legibility at the cost of additional size by doing:

```typescript
const self = this as typeof LitElement;
```

I went with the zero-size-cost option here.
@justinfagnani
Copy link
Contributor

Ugly, but like you said, 0 byte impact. What do we do to ensure we don't regress here?

@justinfagnani
Copy link
Contributor

Also, could we file a bug against tsickle asking them to automatically output the this types for Closure?

@rictic
Copy link
Contributor Author

rictic commented Apr 18, 2019

Looks like one was just filed a couple days ago: angular/tsickle#1015

@rictic
Copy link
Contributor Author

rictic commented Apr 18, 2019

It should be possible to compile with closure compiler as part of the build process. At the moment the round trip into the internal repo is fast enough though that we should catch and fix regressions quickly.

@rictic rictic merged commit f552fc4 into master Apr 18, 2019
@rictic rictic deleted the typed-this branch April 18, 2019 23:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants