Typescript fails in your case because it expects all the fields to be present. Use Record and Partial utility types to solve it.
Record<string, Partial<IPerson>>
interface IPerson {
firstName: string;
lastName: string;
}
var persons: Record<string, Partial<IPerson>> = {
"p1": { firstName: "F1", lastName: "L1" },
"p2": { firstName: "F2" }
};
Explanation.
Alternate.
If you wish to make last name optional you can append a ? Typescript will know that it's optional.
lastName?: string;
https://www.typescriptlang.org/docs/handbook/utility-types.html