错误:
无法获取keys[key]
,因为未定义的索引器属性丢失了
代码:
export type Keys = {
[string]: string,
id?: number,
href?: string,
expand?: Array<string>
}
const keys: Keys = {
};
const requiredKeys: Array<string> = ['aa'];
let keyedUrl: string = 'hi/:aa/test';
function a(keys?: Keys) {
requiredKeys.forEach((key: string) => {
keyedUrl = keyedUrl.replace(`:${key}`, keys[key]);
delete keys[key];
});
}
a(keys);
我该如何解决?