Reputation: 818
Lets assume we have an interface:
interface Foo {
aaa: string
bbb: SomeType
ccc: SomeOtherType
// ... and 100 more
}
I would like to define a type, such that it can receive any of the Foo
interface property types.
Obviously I could do it manually:
type Bar = Foo['aaa'] | Foo['bbb'] // etc.
But that is impractical and not DRY, especially with large interfaces. Is there any better way to define such type, so that it automatically accepts interfaces types?
Upvotes: 0
Views: 622
Reputation: 3253
You can achieve what you want using mapped types:
type Bar = Foo[keyof Foo]
Upvotes: 1