Analog of `valueof` for `keyof` in TypeScript: how to get the type of object values?
Hi everyone! I recently started learning TypeScript and ran into an interesting problem. We all know about `keyof` — it works great when you need to get a union of object keys. For example:
```typescript
interface User {
name: string;
age: number;
email: string;
}
type UserKeys = keyof User; // "name" | "age" | "email"
```
But I need the opposite — to get a union of the *value types* of an object. That is, for the `User` interface, I want to get the type `string | number`, not `"name" | "age" | "email"`.
I tried writing something like `valueof`, but TypeScript throws an error. I googled it — found a similar question on Stack Overflow, but the answers were in English, and I didn't fully understand them.
The specific task: I have a configuration object with fields of different types (str
No answers yet.
Log in to leave an answer