DEV Community

loading...

[TS nugget] Record

webeleon profile image Julien Prugne ・1 min read

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!

Discussion (0)

pic
Editor guide