Skip to content

Support event type information for tools. #4862

Closed

Description

@mhevery

Assume that the user has typed:

<component (click)="$event.?A?" (open)="$event.?B?"

How does the IDE know how to complete the suggestions at ?A? and ?B? sites?

Turns out that ?A? is a DOM event and as such there is no easy way to know what the type of $event is other than having the IDE recognize that it is a DOM event. This implies that the IDE needs to have pre-existing schema. Such schema (#3426) is something that Angular2 compiler needs to have as well so that we can properly validate weather or not a particular element can event a particular DOM event. (Examples is input element emitting a change event). The goal should be to have the event schema for DOM be declared in a way which is tool-able so that tools can take advantage of it.

Completion on ?B? is of different kind, it is an event which is fired from the component element and which does not bubble. In such a case we have to look at the directive annotation so that we can derive the type for $event for completion.

@Component({...})
class MyComponent {
  @Output() open: EventEmitter<SomeType> = new EventEmitter();
  @Output() open: Stream<SomeType> = ...;
}

For an IDE the resolution logic would be to check the schema and derive the type there. If not found check for the directives on the element and see if they fire such an event and what the type is.

Activity

  1. scheglov commented on Oct 26, 2015

    @scheglov
    Contributor

    What type should open have? EventEmitter<SomeType> or Stream<SomeType> or ...? What if it is MyEmitterThatAlsoImplementsStream<int, SomeType, double>?

  2. mhevery commented on Oct 26, 2015

    @mhevery
    ContributorAuthor

    All of your examples implement Stream<T>, so the analyzer would have to walk the type hierarchy and then figure out what T is.

  3. mhevery commented on Oct 27, 2015

    @mhevery
    ContributorAuthor

    This is related to: #3427

  4. scheglov commented on Oct 27, 2015

    @scheglov
    Contributor

    Well, that's the question - what type should event declarations be?
    Something implementing Stream<T>?
    If yes, then sure - extracting the event type T is trivial.

  5. mhevery commented on Oct 27, 2015

    @mhevery
    ContributorAuthor

    Something implementing Stream?

    Yes.

  6. scheglov commented on Oct 27, 2015

    @scheglov
    Contributor

    Very good.
    Yes, the proposed solution works for me.
    Thank you!

  7. robwormald commented on Nov 16, 2015

    @robwormald
    Contributor

    FYI, after the refactor to EventEmitter in ca3986f it's now generic.

  8. scheglov commented on Nov 16, 2015

    @scheglov
    Contributor

    Nice!
    Thank you.

  9. added
    featureLabel used to distinguish feature request from other issues
    on Oct 7, 2016
  10. DzmitryShylovich commented on Mar 11, 2017

    @DzmitryShylovich
    Contributor

    @chuckjaz does language service cover this use case?

  11. chuckjaz commented on Mar 13, 2017

    @chuckjaz
    Contributor

    Yes. @angular/language-service will look at the event type to determine the type of the $event. Any deficiency here should be reported as a bug against langauge-service. Closing this.

  12. angular-automatic-lock-bot commented on Sep 11, 2019

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  13. locked and limited conversation to collaborators on Sep 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: coreIssues related to the framework runtimeeffort2: daysfeatureLabel used to distinguish feature request from other issues

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions