【问题标题】:I'm Getting no-unsafe-call and no-unsafe-assignment eslint error on imported function even though function is typed即使输入了函数,我在导入的函数上也遇到了 no-unsafe-call 和 no-unsafe-assignment eslint 错误
【发布时间】:2021-03-04 06:20:09
【问题描述】:

在导入类型化函数时,我遇到了 no-unsafe-call 和 no-unsafe-assignment eslint 错误。如果函数在同一个文件中声明,错误就会消失。好像eslint无法获取导入函数的返回类型。

在 useWorkspaceMessages.ts

export interface WorkspaceMessage {
  message: string;
  created: string;
}

export default function useWorkspaceMessages(): WorkspaceMessage[] {
  return [];
}

在 app.tsx 中

import useWorkspaceMessages, {
  WorkspaceMessage,
} from 'useWorkspaceMessages';

const workspaceMessages: WorkspaceMessage[] = useWorkspaceMessages();
     ^^^^^^^^^^^^^^^^^^^                      ^^^^^^^^^^^^^^^^^^^^
error  Unsafe assignment of an any value  @typescript-eslint/no-unsafe-assignment
error  Unsafe call of an any typed value  @typescript-eslint/no-unsafe-call

如果我在 app.tsx 中声明 useWorkspaceMessagesWorkspaceMessage 接口,错误就会消失。

【问题讨论】:

  • 在 Node.js 和 TS 4.0.3 上工作正常
  • @Anatoly 谢谢。是的,我的设置可能有问题。我在 ts 4.1.2 上,上周刚刚设置了我的依赖项。不确定是否有什么导致 eslint no 理解导入类型
  • 4.1.2 不是 beta/dev/unstable 版本吗?
  • 看起来是最新的稳定版。但不管怎样,我想通了。我有一个错误.eslint.js parserOptions.project

标签: typescript eslint


【解决方案1】:

找出问题所在。我的.eslint.js有一个错误

我的parserOptions.project 指向了tsconfig.json 的错误目录。遗憾的是,eslint 并没有抱怨这一点。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-01
    • 1970-01-01
    • 2021-08-10
    • 2023-02-26
    • 2017-06-26
    • 2021-06-02
    相关资源
    最近更新 更多