DEV Community

Julien Prugne for Webeleon

Posted on • Edited on

2 3

[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)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs