Declare and initialize a Dictionary in Typescript

前端 未结 6 1070
闹比i
闹比i 2020-12-02 04:22

Given the following code

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

var persons: { [id: string]: IPerson; } = {
   \"p1\": { firstName         


        
6条回答
  •  被撕碎了的回忆
    2020-12-02 04:45

    If you want to ignore a property, mark it as optional by adding a question mark:

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

提交回复
热议问题