TypeScript:隐式具有“任何”类型,因为“字符串”类型的表达式不能用于索引类型

时间:2021-02-16 22:06:20

标签: typescript vue.js

我正在尝试将我在 Vue 中用于处理 i18n 的自定义钩子从 JavaScript 移动到 TypeScript,但我不断收到以下错误:

<块引用>

Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'Languages'. No index signature with a parameter of type 'string' was found on type 'Languages'.

This is the code

1 个答案:

答案 0 :(得分:0)

Languages 的类型为 { en: object },但我怀疑您希望它是一个字符串字典,可以这样输入:

type Languages = {
  [locale: string]: Record<string, string>;
}

demo