Avatar ·

How to get the return type of a function in TypeScript?

Hello everyone! I just started learning TypeScript and ran into a problem. I have a function that returns a complex object, and I need to use the same type elsewhere, but I don't want to duplicate the interface description.\n\nHere's an example:\n\n```typescript\nfunction createUser(name: string, age: number) {\n return {\n id: Math.random().toString(36),\n name: name,\n age: age,\n createdAt: new Date(),\n isActive: true,\n permissions: ['read', 'write']\n };\n}\n\n// How do I get the type of what createUser returns?\n// I want to do something like:\n// type User = ReturnType; // This doesn't work!\n```\n\nI tried using `typeof`, but it returns the type of the function itself, not its return value. Maybe there's some built-in mechanism in TypeSc