【发布时间】:2020-10-02 21:32:41
【问题描述】:
[已解决] 我想知道如何避免与 i18next 相关的 TS6133-error: 'var' is declared but its value is never read?基本上我有一个函数labelForTeaserStyle(style: TeaserStyle),在这行代码中读取:
<Typography variant="subtitle1" color="gray">
Style: {labelForTeaserStyle(style)}
</Typography>
function labelForTeaserStyle(style: TeaserStyle) {
switch (style) {
case TeaserStyle.Default:
return 'Default'
case TeaserStyle.Light:
return 'Light'
case TeaserStyle.Text:
return 'Text'
}
但是,当将 i18next 应用到这行代码时,它会抛出 TS6133-error 'labelForTeaserStyle' is declared but its value is never read。
我已经阅读了关于在导致错误的行之前使用 /* tslint:disable:no-unused-variable */ 的信息,但这无济于事。我读过的另一个建议是在 tsconfig.json 中停用 noUnusedLocals,但这对我来说不是一个选项,因为我想保持此选项处于激活状态。
现在对我来说的问题是,我能否以某种方式嵌入 i18next 代码,以便编译器仍将 labelForTeaserStyle() 识别为正在使用/读取?
使用 i18next 编写代码:
<Typography variant="subtitle1" color="gray">
{t('styleInterpolated', {labelForTeaserStyle(style)})}
</Typography>
按键:
"styleInterpolated": "Style: {{function}}"
【问题讨论】:
-
请将解决方案作为答案发布,以便其他有相同问题的人可以找到。
-
对不起,我是新手。很快就会发布它作为答案。
标签: javascript i18next react-i18next