Skip to content

Overloading functions with specialized parameters not working as expected. #6746

@seshualluvada

Description

@seshualluvada

The below code has a specialized signature for Subscribe function that takes "NotificationClicked" as the event Name and NotificationClickedEventArgs type as the eventArgs parameter. The general signature takes any string as eventName and the base EventArgs as the eventArgs parameter.

My understanding is that typescript should give a compiler error where I am executing the code PublishSubscribe.Subscribe("NotificationClicked", new EventArgs()); because the specialized signature expects a NotificationClickedEventArgs type. As per my observation, typescript is compiling successfully which most likely is a bug. This works correctly on return types though.

class EventArgs{
  EventName: string;
  EventData: any;
}

class NotificationClickedEventArgs extends EventArgs{
  NotificationID: string;
}

class PublishSubscribe{
  static Subscribe:{
    (eventName: "NotificationClicked", eventArgs: NotificationClickedEventArgs):void;
    (eventName: string, eventArgs :EventArgs):void;
  } = (eventName: string, eventArgs: EventArgs) => {  }
}

PublishSubscribe.Subscribe("NotificationClicked", new EventArgs());

Metadata

Metadata

Assignees

No one assigned

    Labels

    QuestionAn issue which isn't directly actionable in code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions