0

Now hava interfae A, want get type B key and value from A. I don't know how define value of type E.

interface A {
    a: {
        name: string;
        age: number;
    };
    b: {
        w: boolean;
        h: symbol;
    };
}
//want
// type B = {
//     name: string;
//     age: number;
//     w: boolean;
//     h: symbol;
// };
type B<T> = { [K in keyof T]: T[K] }[keyof T];
type C<T> = T extends any ? keyof T : never;
type D<T> = T extends any ? T[keyof T] : never;
type E<T> = { [K in C<B<T>>]: T[keyof T][K] };
type G = E<A>;

creanme
  • 11
  • 1
  • `T[keyof T][K]` has some problem – creanme Feb 19 '20 at 08:22
  • Does this answer your question? [Intersection of mapped types](https://stackoverflow.com/questions/47464913/intersection-of-mapped-types) – Phu Ngo Feb 19 '20 at 08:46
  • Already answered here https://stackoverflow.com/a/49279355/1400623 . In your case, `type GetKeys = U extends Record ? K : never; type UnionToIntersection = { [K in GetKeys]: U extends Record ? T : never }; type Wanted = UnionToIntersection ` – Phu Ngo Feb 19 '20 at 08:49

0 Answers0