'onclick' type of 'this' is wrong

Open
#564 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
typescript
Domain
tooling

Research direction

Start by comparing the generated onclick declaration and its this type between TypeScript 3.0 and the 3.1.0-dev.20180804 output. Reproduce the fabric or tingle.js example, then verify that an onclick handler's this type exposes HTMLElement.innerHTML without causing the reported compile error.

Written by the indexing model from the issue text.

Description

bug
document.body.onclick = function() {
    console.log(this.innerHTML.length);
}

The code works in a browser and worked in typescript@3.0. But in typescript@3.1.0-dev.20180804 it is a compile error:

src/a.ts:3:22 - error TS2339: Property 'innerHTML' does not exist on type 'GlobalEventHandlers'.

3     console.log(this.innerHTML.length);

The value of this should be HTMLElement like it was before, not GlobalEventHandlers.
Detected in fabric and tingle.js on DefinitelyTyped.

Dominant language
TypeScript
Stars
740
Forks
474
Avg merge
2d 8h
Merged PRs (30d)
15

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from microsoft/TypeScript-DOM-lib-generator

All issues in microsoft/TypeScript-DOM-lib-generator

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.