1

I want to be able to use a static method like this:

UpdateUrlAction.send('https://google.com')

UpdateCountAction.send(3)

I want to define that UpdateUrlAction.send only takes a string as the parameter, but UpdateCountAction accepts a number. The solution should be based on this general structure:

export default abstract class ChromeMessageAction {
    static action: string

    public static send(payload: Object|string|number) {
        ChromeMessageService.send(this.action, payload)
    }
}

export default class UpdateUrlAction extends ChromeMessageAction {
    action = 'updateUrl'
    payload: string
}

export default class UpdateUrlAction extends ChromeMessageAction {
    action = 'updateCount'
    payload: number
}

Is there some way to define the payload type without overriding the send method?

2
  • 1
    You can checkout this stackoverflow.com/questions/52518125/… Commented Jan 17, 2022 at 19:28
  • @AkashDathan thanks. That worked for me Commented Jan 18, 2022 at 22:28

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.