如何在 React Typescript 应用程序中导入 react-admin? [英] How do I import react-admin in a React Typescript appplication?

查看:67
本文介绍了如何在 React Typescript 应用程序中导入 react-admin?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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 不是一个有效的包,但我在 github 或 stackoverflow 上找不到其他人抱怨这个.我错过了什么吗?据我所知,大部分内容已经迁移到 typescript.

@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.

发现 this 实际上引用了 ts 的问题.然而,自从他们说这需要几个月的时间"已经过去了 5 个月

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

推荐答案

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

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';

这篇关于如何在 React Typescript 应用程序中导入 react-admin?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆