Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 918
Mike Avatar asked Nov 20 '20 20:11

Mike


1 Answers

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.

like image 116
Mike Avatar answered Nov 12 '22 00:11

Mike