Typescript: How to write a new type by using the keys of an Typescript Interface

26 Views Asked by At

I am Typescript developer. I have a situation where I need to pass any keys from a interface as a function parameter. For that, I need to make a new type with the keys of a Interface.

Suppose I have following interface A.

interface A {
 name: string; 
 email: number;
}

I want a new typescript type which will take the keys from the interface "A", combine them with or (|), so that the new type will looks like below:

type B = 'name' | 'email';

Is there any utility Types in Typescript or any suggestions how can I do this?

0

There are 0 best solutions below