Skip to content

Fix the EventTarget.addEventListener and EventTarget.removeEventListener useCapture argument - related to issue #14188 #224

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

Merged
merged 1 commit into from
Mar 30, 2017

Conversation

Diullei
Copy link
Contributor

@Diullei Diullei commented Mar 29, 2017

According to https://dom.spec.whatwg.org/#interface-eventtarget

  • The EventTarget.addEventListener useCapture argument must be (AddEventListenerOptions or boolean)
  • The EventTarget.removeEventListener useCapture argument must be (EventListenerOptions or boolean)

Fix issue microsoft/TypeScript#14188

@msftclas
Copy link

@Diullei,
Thanks for your contribution.
To ensure that the project team has proper rights to use your work, please complete the Contribution License Agreement at https://cla.microsoft.com.

It will cover your contributions to all Microsoft-managed open source projects.
Thanks,
Microsoft Pull Request Bot

@msftclas
Copy link

@Diullei, thanks for signing the contribution license agreement. We will now validate the agreement and then the pull request.

Thanks, Microsoft Pull Request Bot

@Diullei
Copy link
Contributor Author

Diullei commented Mar 29, 2017

This appveyor error is not clear to me. Can someone help me to understand what I'm doing wrong?

@zhengbli
Copy link
Contributor

zhengbli commented Mar 29, 2017

The appveyor error means when replacing the default lib.d.ts with your changed version in TypeScript repo, some TypeScript tests failed (in this case the verifyDefaultLib_webworker test.

The test is a simple check: https://github.com/Microsoft/TypeScript/blob/master/tests/cases/compiler/verifyDefaultLib_webworker.ts
to see if the webworker library file contains error.

At a glance it looks like you defined the two new types only in the dom.generated.d.ts but not in the worker file, so when you use them in the worker file they could not be found.

@Diullei
Copy link
Contributor Author

Diullei commented Mar 29, 2017

Ok, thanks for your help! I'll fix this.

@Diullei
Copy link
Contributor Author

Diullei commented Mar 30, 2017

Hi @zhengbli the appveyor build has been fixed.

@@ -3701,9 +3701,9 @@ declare var Event: {
}

interface EventTarget {
addEventListener(type: string, listener?: EventListenerOrEventListenerObject, useCapture?: boolean): void;
addEventListener(type: string, listener?: EventListenerOrEventListenerObject, useCapture?: boolean | AddEventListenerOptions): void;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the spec, the third argument should be named "options" instead of useCapture, can you also correct this?

}

interface AddEventListenerOptions extends EventListenerOptions {
passive: boolean;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fact that this type is a dictionary in the spec, meaning every property should be optional. Otherwise things like { once: true } would not be accepted. Can you update? The same with EventListenerOptions.capture

@Diullei
Copy link
Contributor Author

Diullei commented Mar 30, 2017

@zhengbli done!

@zhengbli
Copy link
Contributor

Thanks @Diullei !

@zhengbli zhengbli merged commit 537df01 into microsoft:master Mar 30, 2017
zhangbobell added a commit to fex-team/swiper that referenced this pull request Jun 28, 2017
…ontainer is document.body

BUG: when $container is document.body, chrome version higher than 56 will display a warning, since the default value of passive is true on document. see https://www.chromestatus.com/features/5093566007214080

FIX: add {passive: false} to add/removeEventListener, since Typescript’s default signature of `option` in addEventListener is boolean, and in removeEventListener is bool | targetEventOption, add static cast to any to avoid this bug.

microsoft/TypeScript#9548
microsoft/TypeScript-DOM-lib-generator#224

TODO: may need remove this cast in later Typescript version
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants