Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I’m just thinking of separate functions like this, which you can do in many languages:

add(n: number)

add(s: string)

In TypeScript (and also in C and Objective-C) you need to give them different names:

addNumber(n: number)

addString(s: string)

But see also brundolf’s reply -- if you have a single function that happens to take multiple overloads, TS does let you declare each overload; but it still needs a single implementation (likely with some runtime dispatching) in that case. I haven’t used that much myself, but maybe I should give it a go!



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: