【问题标题】:import react-admin breaks tsc build导入 react-admin 中断 tsc 构建
【发布时间】:2021-03-21 09:36:09
【问题描述】:

我使用 react admin 和 typescript。
我更喜欢使用strict 类型检查。所以当我运行tsc 时,react admin 向我显示了一个implicitly any 错误。
尽管我使用了"skipLibCheck": true,但错误来了。我该如何解决?

node_modules/ra-core/src/auth/useCheckAuth.ts:101:26 - error TS7006: Parameter 'error' implicitly has an 'any' type.

101 const getErrorMessage = (error, defaultMessage) =>
                             ~~~~~

下面是我的 tsconfig 文件。

{
  "compilerOptions": {
    "baseUrl": ".",
    "target": "es5",
    "lib": ["dom", "dom.iterable", "esnext"],
    "allowJs": true,
    "skipLibCheck": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "noEmit": true,
    "esModuleInterop": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "jsx": "preserve",
    "paths": {
      "@components/*": ["components/*"],
      "@styles/*": ["styles/*"],
      "@lib/*": ["lib/*"],
      "@pages/*": ["pages/*"]
    }
  },
  "exclude": ["node_modules"],
  "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"]
}

【问题讨论】:

    标签: reactjs typescript node-modules react-admin tsc


    【解决方案1】:

    我在我的代码库中发现了一个问题,这就是邪恶的根源。

    import {
      CreateResult,
      DeleteResult,
      GetListResult,
      GetManyReferenceResult,
      GetManyResult,
      GetOneResult,
      UpdateResult,
    } from 'ra-core/src/types';
    

    如果我像上面那样从 'ra-core/src/types' 导入 pkgs,它会抛出 ts 错误。

    您可以通过从 'ra-core' 导入包来修复它,如下所示。

    import {
      CreateResult,
      DeleteResult,
      GetListResult,
      GetManyReferenceResult,
      GetManyResult,
      GetOneResult,
      UpdateResult,
    } from 'ra-core';
    

    【讨论】:

    • 很棒的发现。谢谢!我永远不会找到它?
    猜你喜欢
    • 2023-03-18
    • 2017-09-02
    • 1970-01-01
    • 2019-02-08
    • 2020-03-09
    • 2021-07-15
    • 1970-01-01
    • 2022-07-15
    • 1970-01-01
    相关资源
    最近更新 更多