Avatar ·

Constructor Overloading in TypeScript: How to Implement Correctly?

Hello everyone! I started learning TypeScript and encountered a problem with constructor overloading. In other languages (like Java or C#), I'm used to being able to declare multiple constructors with different parameters. But in TypeScript, it doesn't work the same way. Let's say I want to create a `User` class that can be initialized either with a string (email) or with an object containing name and age. I tried writing it like this: ```typescript class User { constructor(email: string) { // ... } constructor(name: string, age: number) { // ... } } ``` But TypeScript throws an error: "Duplicate function implementation". I understand that JavaScript doesn't have real overloading, but how should I handle this? I need the class to be creatable in different ways: 1. `new User("john@example.com")` — th