错误:
无法获取 keys[key]
因为undefined中缺少索引器属性
码:
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);
我该如何解决?