【问题标题】:How to resolve the issue "unused expression, expected an assignment or function call"?如何解决“未使用的表达式,需要赋值或函数调用”的问题?
【发布时间】:2019-06-12 01:30:09
【问题描述】:

我已尝试在我的 react 应用程序 (App.tsx) 中导入 json 文件。

App.tsx

import * as currencies from './currencies.json';

我的 Json 文件将如下所示:

{
  "main": {
     "numbers": {
        "currencies": {
         }
      }
   }
}

在运行应用程序时,它会抛出以下错误

(1,1):未使用的表达式,需要赋值或函数调用

经过进一步分析,我在 src 文件夹中添加了 typings.d.ts 文件

declare module "*.json" {
    const value: any;
    export default value;
}

但我们仍然面临同样的问题。谁能建议如何解决这个问题?

【问题讨论】:

  • 从'./currencies.json'导入货币;
  • @ma_dev_15:我试过了,但是不行

标签: reactjs react-native


【解决方案1】:

我通过在 tslint.json 文件中包含以下代码块解决了同样的问题

"linterOptions": {
  "exclude": [
    "*.json",
    "**/*.json"
  ]
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-01-26
    • 2015-05-22
    • 2023-03-26
    • 2021-01-09
    • 2012-02-23
    • 1970-01-01
    • 1970-01-01
    • 2020-03-30
    相关资源
    最近更新 更多