Does Typescript support “subset types”?

后端 未结 7 1750
青春惊慌失措
青春惊慌失措 2020-12-29 02:36

Let\'s say I have an interface:

interface IUser {
  email: string;
  id: number;
  phone: string;
};

Then I have a function that expects a

7条回答
  •  死守一世寂寞
    2020-12-29 02:54

    You can declare some or all fields as optional fields.

    interface IUser {
      email: string; // not optional
      id?: number; // optional 
      phone?: string; // optional
    };
    

提交回复
热议问题