DEV Community

Julien Prugne for Webeleon

Posted on • Edited on

[TS nugget] Record<Keys, Type>

For years now I wrote my data bags like this.

export inteface Foo {
  bar: {
    [key: string]: string;
  };
}
Enter fullscreen mode Exit fullscreen mode

To be honest, I always felt kind of disgusted about it...
But today, I learned the elegant way.

export interface Foo {
  bar: Record<string, string>
}
Enter fullscreen mode Exit fullscreen mode

May the elegant code be with you my coding friends!

To the doc!

Top comments (0)