typescript dynamic dict 1

typescript dynamic dict

interface SampleObject {
  color?: string;
  width?: number;
  [propName: string]: number | string;
}

Here is what the above code is Doing:
1. We’re defining a type called SampleObject.
2. We’re saying that SampleObject has three properties: color, width, and any other property whose name is a string.
3. We’re saying that the color property is a string, the width property is a number, and any other property is either a number or a string.

Similar Posts