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

customEvent.emit() returns boolean instead of CustomEvent #1996

Closed
tricki opened this issue Nov 7, 2019 · 0 comments · Fixed by #2017
Closed

customEvent.emit() returns boolean instead of CustomEvent #1996

tricki opened this issue Nov 7, 2019 · 0 comments · Fixed by #2017
Labels

Comments

@tricki
Copy link
Contributor

tricki commented Nov 7, 2019

Stencil version:

 @stencil/core@1.7.5

I'm submitting a:

[x] bug report
[ ] feature request
[ ] support request => Please do not submit support requests here, use one of these channels: https://stencil-worldwide.herokuapp.com/ or https://forum.ionicframework.com/

Current behavior:
this.customEvent.emit() returns a boolean even though according to the declaration it should return CustomEvent<T>.

Expected behavior:
Either emit() should return a CustomEvent or the type declaration should be changed.

Steps to reproduce:
Emit any custom event in a Stencil component and check its return type.

Related code:

import { Component, Event, EventEmitter } from '@stencil/core';

@Component({
  tag: 'my-component'
})
export class MyComponent {

  @Event() someEvent: EventEmitter;

  componentDidLoad() {
    if (typeof this.someEvent.emit() === 'boolean') {
      alert('Boolean was returned');
    }
  }

Type declaration:

export interface EventEmitter<T = any> {
    emit: (data?: T) => CustomEvent<T>;
}

Other information:
The implementation of emit() returns the result of dispatchEvent which, according to MDN, is a boolean indicating whether the event was cancelled (i.e. at least one of the handlers called event.preventDefault()).

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 a pull request may close this issue.

1 participant