reactjs - ฉันจะนำเข้า react-admin ในแอปพลิเคชัน React Typescript ได้อย่างไร?
ฉันกำลังพยายามตั้งค่าแอป react-admin ใน TypeScript และฉันยังไม่สามารถหาวิธีนำเข้า 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 ฉันกำลังพลาดอะไรไปหรือเปล่า? เท่าที่ฉันเห็น ส่วนใหญ่ได้ย้ายไปใช้ TypeScript แล้ว
แก้ไข: พบอันนี้ซึ่งจริง ๆ อ้างอิงถึงปัญหากับ ts แต่อย่างไรก็ตามมันผ่านมาแล้ว 5 เดือนนับตั้งแต่พวกเขาพูดว่า "มันจะใช้เวลาหลายเดือน"
คำตอบ #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';
