问题
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"
回答1:
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';
来源:https://stackoverflow.com/questions/58838216/how-do-i-import-react-admin-in-a-react-typescript-appplication