hegel icon indicating copy to clipboard operation
hegel copied to clipboard

Function overloading with different result type

Open juanluispaz opened this issue 4 years ago • 1 comments

¿How I can define and implement an overloaded function with different result type?

Example:

function generate(type: 'number' | 'string') {
    if (type === 'number') {
        return 1234
    } else {
        return 'hello'
    }
}

const aNumber = generate('number') // I expect the result type as number
const aString = generate('string') // I expect the result type as string

Thanks for this amazing work.

juanluispaz avatar May 19 '20 19:05 juanluispaz

Hello. "Function overloading" is in plans, so, it will be added after we will fix known bugs. Thank you for the contribution ^_^

JSMonk avatar May 19 '20 19:05 JSMonk