Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I import react-admin in a React Typescript appplication?

I'm trying to set up a react-admin app in typescript and I can't quite figure out how to import react-admin. It gives me the (simple) error saying

"Could not find a declaration file for module 'react-admin'. 
'.../node_modules/react-admin/lib/index.js' implicitly has an 'any' type.
Try `npm install @types/react-admin` if it exists or add a new declaration (.d.ts)
 file containing `declare module 'react-admin';`"

@types/react-admin is not a valid package but I couldn't find anyone else complaining about this on github or stackoverflow. Am I missing something? As far as I can see, most things have already been migrated to typescript.

Edit: Found this which actually references the problem with ts. However it's been 5 months since they said "it will take months"

like image 208
Mike Avatar asked Nov 13 '19 13:11

Mike


1 Answers

Current version of react-admin does not export types definition. To make your project to compile you need to create index.d.ts file and modify tsconfig.json.

├── @types
│   └── react-admin
│       └── index.d.ts
└── tsconfig.json
// tsconfig.json

{
  ...
  "compilerOptions": {
    ...
    "typeRoots": ["./@types"],
    ...
  },
  ...
}
// index.d.ts
declare module 'react-admin';
like image 158
Maciek Przybylski Avatar answered Oct 09 '22 07:10

Maciek Przybylski