Search code examples
reactjstypescriptnode-modulesreact-admintsc

import react-admin breaks tsc build


I use react admin, with typescript.
I prefer to use strict type checking. So when I run tsc, react admin shows me an implicitly any error.
Eventhough I used "skipLibCheck": true, but the error comes. How can I fix it?

node_modules/ra-core/src/auth/useCheckAuth.ts:101:26 - error TS7006: Parameter 'error' implicitly has an 'any' type.

101 const getErrorMessage = (error, defaultMessage) =>
                             ~~~~~

Below, my tsconfig file.

{
  "compilerOptions": {
    "baseUrl": ".",
    "target": "es5",
    "lib": ["dom", "dom.iterable", "esnext"],
    "allowJs": true,
    "skipLibCheck": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "noEmit": true,
    "esModuleInterop": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "jsx": "preserve",
    "paths": {
      "@components/*": ["components/*"],
      "@styles/*": ["styles/*"],
      "@lib/*": ["lib/*"],
      "@pages/*": ["pages/*"]
    }
  },
  "exclude": ["node_modules"],
  "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"]
}

Solution

  • I found a problem in my codebase, here is the source of evil.

    import {
      CreateResult,
      DeleteResult,
      GetListResult,
      GetManyReferenceResult,
      GetManyResult,
      GetOneResult,
      UpdateResult,
    } from 'ra-core/src/types';
    

    If I import pkgs from 'ra-core/src/types' like above, It throws ts error.

    You can fix it by import packages from 'ra-core' like below.

    import {
      CreateResult,
      DeleteResult,
      GetListResult,
      GetManyReferenceResult,
      GetManyResult,
      GetOneResult,
      UpdateResult,
    } from 'ra-core';