Reputation: 364
I have union like:
type A = "a" | "b" | "c";
And I would like to have an interface like:
interface B {
[index: A]: string
}
But I would want this interface to force to have all of the options of union type, so the final interface would look like this:
interface B {
a: string;
b: string;
c: string;
}
Is it possible to achieve?
Upvotes: 0
Views: 120
Reputation: 2822
You can achieve this using mapped type:
type B = {
[K in A]: string
};
Upvotes: 1