3 ms·
How do you give the overloads different names? Can you give a little example?
by adamddev1 4y ago
How do you give the overloads different names? Can you give a little example?
- iainmerrick 4y agoI’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!