google / google/closure-compiler

"new EventTarget()" or "extends EventTarget" throw errors

Open
#3,143 6 comments 2 reactions 0 assignees View on GitHub
triage-done
Dominant language
JavaScript
Stars
7.7k
Forks
1.2k
Avg merge
2d 12h
Merged PRs (30d)
6

Description

Closure compiler should allow instantiating or extending the native EventTarget class, see [1]. Also see [2] which depicts that this is already implemented in Chrome.

Unfortunately closure compiler throws an error for both these cases.
```js
const foo = new EventTarget();
class MyTarget extends EventTarget {}
```

```
JSC_NOT_A_CONSTRUCTOR: cannot instantiate non-constructor at line 1 character 12
const foo = new EventTarget();
^
JSC_CONFLICTING_EXTENDED_TYPE: MyTarget cannot extend this type; constructors can only extend constructors at line 2 character 0
class MyTarget extends EventTarget {}
^
```

Even if this is too hard to fix in the default JS compiler externs, there should be a command line flags that allows using a different set of externs to achieve this.

See previous PR about this at https://github.com/google/closure-compiler/pull/2988, which never landed.

[1] https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/EventTarget
[2] https://www.chromestatus.com/features/5721972856061952

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.