流错误“未定义的索引器属性丢失”

时间:2018-10-30 00:33:59

标签: flowtype

错误:

无法获取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);

Live Example

我该如何解决?

0 个答案:

没有答案