How to declare and initialize a Dictionary in Typescript

0 votes

Why is this code not working as intended?

interface IPerson {
   firstName: string;
   lastName: string;
}

var persons: { [id: string]: IPerson; } = {
   "p1": { firstName: "F1", lastName: "L1" },
   "p2": { firstName: "F2" }
};
May 31, 2022 in TypeSript by Logan
• 2,140 points
7,798 views