Function Overloading in TypeScript: How to Properly Declare and Use?
Hello everyone! I've just started learning TypeScript after JavaScript and came across a topic I don't understand — function overloading. \n\nIn JavaScript, I'm used to writing functions that can accept different types of arguments and checking them inside using `typeof` or `instanceof`. For example, I have a function that should accept either a string or a number, and depending on that, perform different operations. In JS, I did this:\n\n```typescript\nfunction format(input) {\n if (typeof input === 'string') {\n return input.trim();\n } else if (typeof input === 'number') {\n return input.toFixed(2);\n }\n}\n```\n\nBut in TypeScript, I want to describe the types for this function. I tried to write:\n\n```typescript\nfunction format(input: string | number): string {\n // ...\n}\n```