Avatar ·

How to get TypeScript interface keys as an array of strings?

Hi everyone! I started learning TypeScript and encountered a problem that I can't solve. I have an interface describing an object structure, and I need to get a list of its keys as an array of strings for further use in code (e.g., for validation or form generation). Here's an example of my interface: ```typescript interface User { name: string; age: number; email: string; } ``` I want to get the array `['name', 'age', 'email']` automatically based on this interface. I tried using `Object.keys()`, but TypeScript complains that I'm passing a type, not an object. I tried various approaches with `keyof`, but I only get a union of strings, not an array. Please advise how to do this correctly? I need a TypeScript solution that preserves the types.