TypeScript: How to show all type members instead of higher order types

Solution for TypeScript: How to show all type members instead of higher order types
is Given Below:

I’m making some mapped types in my project and I’m pretty sure they’re working correctly, but something that would make it much easier would be seeing what the types explicitly map to.

type OptionalKeys<T> = Exclude<
  {
    [K in keyof T]: T extends Record<K, T[K]> ? never : K;
  }[keyof T],
  undefined
>;

type RequiredKeys<T> =  Exclude<keyof T, OptionalKeys<T>>;

interface Foo {
  a: Date;
  b?: Date;
}

type StringFoo = (
  Partial<Record<OptionalKeys<Foo>, string> &
  Record<RequiredKeys<Foo, string>>
);

This works great, except when I mouse over the type to inspect it, this is what I see

type StringFoo = Partial<Record<"b", string>> & Record<"a", string>

That’s kind of opaque. Is there a way to make it show up as this instead?

type StringFoo = {
  b?: string;
} & {
  a: string;
}

Thanks!

Use braces with an index signature rather than the Record type:

type StringFoo = (
  {[key in OptionalKeys<Foo>]?: string} & 
  {[key in RequiredKeys<Foo>]: string}
);

// {
//     b?: string | undefined;
// } & {
//     a: string;
// }