我是非常(非常)新的前沿技术,特别是反应和类型记录。
我的问题是在尝试做一件简单的事情,即使用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和更多的古典主义编辑器代码。/src/classiceditor文件夹实际上存在node_modules和/@ckeditor/ckeditor5-editor-classic/src/classiceditor.js
知道我错过了什么吗?
发布于 2020-01-07 21:10:14
看起来@ckeditor/ckeditor 5-react不提供任何类型,也没有在DefinitelyTyped中键入,所以您不能在类型记录中轻松地使用它。
如果要将@ckeditor/ckeditor5-react与类型一起使用,则必须自己键入。
例如:
在项目中,声明一个文件types/@ckeditor/ckeditor5-react/index.d.ts。在此文件中添加以下(非常不完整)类型:
declare module '@ckeditor/ckeditor5-react' {
export default class Ckeditor extends React.Component {
constructor({disabled}: {disabled?: boolean}) // this part needs to be fullfilled with your needs
}
}这样,您就可以在您的react应用程序中以这种方式使用CKeditor:
export function UseCKE() {
return <Ckeditor disabled={true}/>;
}发布于 2021-01-31 03:20:25
对于那些仍然在寻找更好的解决方案的人,我从Github那里找到了这个解决方案。
您需要创建文件./types/ckeditor/index.d.ts并将其写入
declare module '@ckeditor/ckeditor5-react';
declare module '@ckeditor/ckeditor5-build-classic';发布于 2020-06-02 02:25:31
对于其他有相同问题的人,您也可以尝试声明一个文件类型/@ckeditor/index.d.ts,并添加以下内容
declare module '@ckeditor/*' {
const classes: any;
export default classes;
}在与@ckeditor/ckeditor5-build-classic打交道时,接受的答案对我不起作用
https://stackoverflow.com/questions/59636065
复制相似问题