TSConfig paths and "Unsafe call of an `any` typed value" on imports

70 Views Asked by At

I have a method in a service e.g. -

// file some-service.ts
export const getKey = (key: string) => key;

and use it as follows with import alias -

import * as someService from '~/shared/services/some-service';

// eslint reports on this line
someService.getKey('test');

ESLint reports on it -

Unsafe call of an `any` typed value. (eslint@typescript-eslint/no-unsafe-call)
Unsafe member access .getKey on an `any` value. (eslint@typescript-eslint/no-unsafe-member-access)

when i'm changing the path to be relative instead, TS doesn't complain -

import * as someService from '../../services/some-service';

someService.getKey('test');

Afaiu the issue is related to the way aliases like ~ are setup. The app is a monorepo with tsconfig.json in the root folder -

{
  "extends": "tsconfig/base.json"
}

and also in the ./apps/my-app/tsconfig.json -

{
  "extends": "tsconfig/base.json",
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "~/*": ["./src/*"]
    }
  }
}

I'm not sure what exactly is missing in this setup, it would be great if each app could setup aliases by itself

  • Typescript v4.8.4
  • ESLint v8.56.0
  • @typescript-eslint/eslint-plugin v6.19.1
0

There are 0 best solutions below