簡體   English   中英

即使輸入了函數,我也會在導入的函數上出現 no-unsafe-call 和 no-unsafe-assignment eslint 錯誤

[英]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 錯誤。 如果函數在同一個文件中聲明,錯誤就會消失。 eslint 似乎無法獲取導入函數的返回類型。

在使用WorkspaceMessages.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接口,錯誤就會消失。

弄清楚出了什么問題。 我的.eslint.js有錯誤

parserOptions.project指着TE錯誤的目錄tsconfig.json 可悲的是,eslint 並沒有抱怨這一點。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM