简体   繁体   English

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

[英]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.我正在尝试在 typescript 中设置一个 react-admin 应用程序,但我不太清楚如何导入 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. @types/react-admin 不是有效的 package 但我在 github 或 stackoverflow 上找不到其他人抱怨此问题。 Am I missing something?我错过了什么吗? As far as I can see, most things have already been migrated to typescript.据我所见,大多数东西已经迁移到 typescript。

Edit: Found this which actually references the problem with ts.编辑:发现这个实际上引用了 ts 的问题。 However it's been 5 months since they said "it will take months"然而,自从他们说“这将需要几个月”以来已经 5 个月了

Current version of react-admin does not export types definition.当前版本的 react-admin 不导出类型定义。 To make your project to compile you need to create index.d.ts file and modify tsconfig.json .要编译您的项目,您需要创建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';

if the issue exist after after the.d.ts file creation, use "noImplicitAny": false, in your tsconfig.json如果在创建 .d.ts 文件后问题存在,请在 tsconfig.json 中使用"noImplicitAny": false,

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM