首页 > 解决方案 > 如何找到我的 typescript/react 模块的声明?

问题描述

我在前端技术方面非常(非常)新,特别是反应和打字稿。

当尝试做一个简单的事情是使用反应组件时,我的问题出现了https://github.com/ckeditor/ckeditor5

所以我去看了例子,发现了这个:

https://github.com/ckeditor/ckeditor5-react-example/blob/master/package.json

我正在尝试将ckeditor包含在ClassicEditor模块中

所以我在我的 package.json 中添加了这个

"@ckeditor/ckeditor5-editor-classic": "^12.0.0",
"@ckeditor/ckeditor5-essentials": "^11.0.0",
"@ckeditor/ckeditor5-paragraph": "^11.0.0",
"@ckeditor/ckeditor5-react": "^1.1.2",

并在此处检查实现https://github.com/ckeditor/ckeditor5-react-example/blob/master/src/App.js

我需要为打字稿导入模块定义(我猜)

import CKEditor from '@ckeditor/ckeditor5-react';

// NOTE: We use editor from source (not a build)!
import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classiceditor';

所以,这部分有这个奇怪的注释,但发生在我的项目中不起作用(说丢失并且找不到它)

知道我还能做些什么来添加它吗?我尝试删除该/src/classiceditor部分,但仍然丢失。

我做了一个npm install,我可以看到带有 package.json 的 classiceditor 代码等等...... /src/ classiceditor 文件夹实际上存在 node_modules/@ckeditor/ckeditor5-editor-classic/src/classiceditor.js

知道我错过了什么吗?

标签: javascriptreactjstypescriptckeditor

解决方案


对于那些仍在寻找更好解决方案的人,我从Github找到了这个解决方案。

您需要创建文件./types/ckeditor/index.d.ts并写入

declare module '@ckeditor/ckeditor5-react';
declare module '@ckeditor/ckeditor5-build-classic';

推荐阅读