microsoft / microsoft/TypeScript
TypeScript doesn't allow event : CustomEvent in addEventListener
Open
@weswigham is already working on this.
Since Nov 6, 2019.
Domain: lib.d.ts
Needs Investigation
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
I'm using Visual Studio Code - Insiders v 1.29.0-insider
In my TypeScript project, I'm trying to write the following code:
buttonEl.addEventListener( 'myCustomEvent', ( event : CustomEvent ) => {
//do something
} );
The problem is that the CustomEvent type gives me the error shown below. If I replace CustomEvent with Event, then there is no error, but then I have difficulty getting event.detail out of the event listener.
"resource": "/c:/Users/me/Documents/app/file.ts",
"owner": "typescript",
"code": "2345",
"severity": 8,
"message": "Argument of type '(event: CustomEvent<any>) => void' is not assignable to parameter of type 'EventListenerOrEventListenerObject'.\n Type '(event: CustomEvent<any>) => void' is not assignable to type 'EventListener'.\n Types of parameters 'event' and 'evt' are incompatible.\n Type 'Event' is not assignable to type 'CustomEvent<any>'.\n Property 'detail' is missing in type 'Event'.",
"source": "ts",
"startLineNumber": 86,
"startColumn": 44,
"endLineNumber": 86,
"endColumn": 72
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.