简体   繁体   中英

I'm Getting no-unsafe-call and no-unsafe-assignment eslint error on imported function even though function is typed

I'm getting no-unsafe-call and also no-unsafe-assignment eslint errors when importing a typed function. If the function is declared in the same file, the error goes away. It seems that eslint is not able to get the return type of the imported function.

In useWorkspaceMessages.ts

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

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

In 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

If I declare useWorkspaceMessages and the WorkspaceMessage interface in app.tsx the error goes away.

Figured out what was wrong. I had a mistake in my .eslint.js

my parserOptions.project was pointing to te wrong directory for tsconfig.json . Sadly, eslint does not complain about this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM