在一个角7项目中,我有以下打字稿接口:
export interface Request {
expand: string;
limit: number;
}
然后,我用它,如下所示:
let request: Request = { expand: 'address' };
我得到一个错误,因为我没有设置limit
...
我怎样才能让limit
可选的界面?
打字稿2.1引入了Partial type:
let request: Partial<Request> = { expand: 'address' };
另一种方法是使limit
可选:
export interface Request {
expand: string;
limit?: number;
}