简体   繁体   English

属性“模块”在类型“ typeof MyEditor”上不存在。ts(2339)

[英]Property 'modules' does not exist on type 'typeof MyEditor'.ts(2339)

Trying to add a rich text editor and am running across the error in the title. 尝试添加富文本格式编辑器,并在标题中遇到错误。 Basically I need to know how in TypeScript to declare what properties my class component has. 基本上,我需要知道如何在TypeScript中声明类组件具有的属性。 This is a react project. 这是一个反应项目。 Anyone have any ideas? 有人有想法么? Here is the code. 这是代码。 The part i'm running into is when it comes to the .modules. 我遇到的部分是关于.modules的。

import React from 'react';
import ReactQuill from 'react-quill'; // ES6

type modules = {

}
class MyEditor<modules> extends React.Component<any, any, {}> {
    constructor(props) {
        super(props)
        this.state = { text: this.props.text } // You can also pass a Quill Delta here
        this.handleChange = this.handleChange.bind(this)
    }
    shouldComponentUpdate(nextProps) { // error here
        if (nextProps.className) {
            return false
        }
    }
    handleChange(value) {
        this.setState({ text: value })
        this.props.gatherBody(value)
    }

    render() {

        return (

            <ReactQuill value={this.state.text}
                onChange={this.handleChange}
                modules={MyEditor.modules}
            />
        )
    }
}
MyEditor.modules = {
    toolbar: [
        [{ 'header': '1' }, { 'header': '2' }, { 'font': [] }],
        [{ size: [] }],
        ['bold', 'italic', 'underline', 'strike', 'blockquote'],
        [{ 'list': 'ordered' }, { 'list': 'bullet' },
        { 'indent': '-1' }, { 'indent': '+1' }],
        ['clean']
    ],
    clipboard: {
        // toggle to add extra line breaks when pasting HTML:
        matchVisual: false,
    }
}
export default MyEditor

You have to declare a static property inside the component. 您必须在组件内部声明一个静态属性。 Code below. 下面的代码。

import React, { Component } from 'react';
import ReactQuill from 'react-quill'; // ES6


class MyEditor extends React.Component<any, any, {}> {
    constructor(props) {
        super(props)
        this.state = { text: this.props.text } // You can also pass a Quill Delta here
        this.handleChange = this.handleChange.bind(this)
    }
    static modules: {} = {
        modules: {}
    }
    shouldComponentUpdate(nextProps) { // error here
        if (nextProps.className) {
            return false
        }
    }
    handleChange(value) {
        this.setState({ text: value })
        this.props.gatherBody(value)
    }

    render() {

        return (

            <ReactQuill value={this.state.text}
                onChange={this.handleChange}
                modules={MyEditor.modules}
            />
        )
    }
}
MyEditor.modules = {
    toolbar: [
        [{ 'header': '1' }, { 'header': '2' }, { 'font': [] }],
        [{ size: [] }],
        ['bold', 'italic', 'underline', 'strike', 'blockquote'],
        [{ 'list': 'ordered' }, { 'list': 'bullet' },
        { 'indent': '-1' }, { 'indent': '+1' }],
        ['clean']
    ],
    clipboard: {
        // toggle to add extra line breaks when pasting HTML:
        matchVisual: false,
    }
}
export default MyEditor

暂无
暂无

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

相关问题 类型'typeof Observable'.ts(2339)上不存在属性'interval' - Property 'interval' does not exist on type 'typeof Observable'.ts(2339) 类型 'typeof import("/home/kartik/Desktop/Ecommerce/ecommerce/node_modules/firebase/index")' 上不存在属性 'auth'。 ts(2339) - Property 'auth' does not exist on type 'typeof import("/home/kartik/Desktop/Ecommerce/ecommerce/node_modules/firebase/index")'. ts(2339) TS2339:类型“ {}”上不存在属性“ props” - TS2339: Property 'props' does not exist on type '{}' 错误TS2339:类型“字符串”上不存在属性“默认”。** - Error TS2339: Property 'Default' does not exist on type 'string'.** Typescript 通用:“T”类型上不存在属性“pass”.ts(2339) - Typescript generic : Property 'pass' does not exist on type 'T'.ts(2339) 类型 'void | 上不存在属性 'subscribe' 可观察的<user> '。 ts(2339)</user> - Property 'subscribe' does not exist on type 'void | Observable<User>'. ts(2339) TS2339:“元素”类型上不存在属性“样式” - TS2339: Property 'style' does not exist on type 'Element' “TypedResponse”类型上不存在属性<never> '.ts(2339)</never> - Property does not exist on type 'TypedResponse<never>'.ts(2339) 错误 TS2339:类型“CustomerTransfert[]”上不存在属性“num” - error TS2339: Property 'num' does not exist on type 'CustomerTransfert[]' 输入字段上的“TS2339:属性...在类型...上不存在” - “TS2339: Property … does not exist on type …”, on input field
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM