小编典典

如何在React Typescript应用程序中导入react-admin?

reactjs

我正在尝试在打字稿中设置一个react-admin应用程序,但我不太清楚如何导入react-admin。它给了我(简单)错误说

"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不是有效的程序包,但是我找不到其他人在github或stackoverflow上对此抱怨。我想念什么吗?据我所知,大多数东西已经迁移到打字稿上了。

编辑:发现实际上引用了ts问题。但是距离他们说“需要几个月”已经过去了5个月。


阅读 287

收藏
2020-07-22

共1个答案

小编典典

当前版本的react-admin不导出类型定义。为了使您的项目能够编译,您需要创建index.d.ts文件并进行修改tsconfig.json

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



// tsconfig.json

{
  ...
  "compilerOptions": {
    ...
    "typeRoots": ["./@types"],
    ...
  },
  ...
}



// index.d.ts
declare module 'react-admin';
2020-07-22