typescript - TypeScript:隐式具有“任何”类型,因为“字符串”类型的表达式不能用于索引类型
问题描述
我正在尝试将我在 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'.
解决方案
Languages
输入为{ en: object }
,但我怀疑您希望它是一个字符串字典,可以这样输入:
type Languages = {
[locale: string]: Record<string, string>;
}
推荐阅读
- python - 根据条件从列表中删除元素
- jquery - 没有在分页上被取消选择 - 数据表
- android - 无论如何在这里访问java代码中的gradle ext属性吗?
- node.js - npm open 在服务器中部署时不起作用?
- html - 如何在导航栏中垂直对齐按钮?
- javascript - 单击按钮时的 jQuery 动画表单
- python - DJANGO HEROKU:django.db.migrations.exceptions.InconsistentMigrationHistory:
- java - Dynamodb 本地连接被 Java 拒绝
- azure - 如何在通过 ARM 模板创建部署时从系统变量中读取输入
- makefile - Makefile 动态变量作为先决条件