#Programmatically reuse interface for another similar type?

2 messages · Page 1 of 1 (latest)

agile arch
#

Imagine I have an interface:

  interface Foo {
     bar: SomeTypeA;
     bitz: SomeTypeB;
  }

And I want to use this interface to create another another interface that looks like this:

   interface Foo2 {
       bar: WrapperType<SomeTypeA>;
       bitz: WrapperType<SomeTypeB>;
   }

How would I do this programmatically, so that Foo2 is defined merely by referencing Foo instead of having to retype the structure as is?

hoary fable
#

@agile arch You'd use a mapped type:

type Foo2 = {
   [K in keyof Foo]: WrapperType<Foo[K]>
}