Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将私有变量从ReactJS转换为TypeScript?_Reactjs_Typescript - Fatal编程技术网

如何将私有变量从ReactJS转换为TypeScript?

如何将私有变量从ReactJS转换为TypeScript?,reactjs,typescript,Reactjs,Typescript,我试图将ReactJS代码转换为TypeScript,在React中偶然发现了一些代码,其中声明了私有变量。但是当我将.jsx文件转换为.tsx时,会出现如下错误 类型“SampleCode.ts(2339)”上不存在属性“\u element” 下面是我试图转换的ReactJS的片段 export class SampleCode extends ParentCode{ constructor(domElement: HTMLElement){ super();

我试图将ReactJS代码转换为TypeScript,在React中偶然发现了一些代码,其中声明了私有变量。但是当我将.jsx文件转换为.tsx时,会出现如下错误

类型“SampleCode.ts(2339)”上不存在属性“\u element”

下面是我试图转换的ReactJS的片段

export class SampleCode extends ParentCode{
    constructor(domElement: HTMLElement){
         super();
         this._element = domElement;
         this._d3SvgContainer = d3.select(this._element).append('svg');
    }
 }

这只是代码的一部分,但我想它足以回答我的问题。

您可以在类的主体中定义它们

export class SampleCode extends ParentCode{

    private _element;
    private _d3SvgContainer;

    constructor(domElement: HTMLElement){
         super();
         this._element = domElement;
         this._d3SvgContainer = d3.select(this._element).append('svg');
    }
 }

您可以在类的主体中定义它们

export class SampleCode extends ParentCode{

    private _element;
    private _d3SvgContainer;

    constructor(domElement: HTMLElement){
         super();
         this._element = domElement;
         this._d3SvgContainer = d3.select(this._element).append('svg');
    }
 }

类型设置如何?取决于类型:private\u元素:any;私人(d3SvgContainer):任何;;将工作(取决于你的皮棉有多严格)。但是你可以在HtmleElement界面中挖掘这些元素的实际类型。看起来很公平,谢谢!如果这有帮助:_元素将是HtmleElement类型,_d3SvgContainer取决于c3返回的内容(抱歉,不熟悉库类型)类型设置如何?取决于类型:private _元素:any;私人(d3SvgContainer):任何;;将工作(取决于你的皮棉有多严格)。但是你可以在HtmleElement界面中挖掘这些元素的实际类型。看起来很公平,谢谢!如果这有帮助:_元素将是HtmleElement类型,_d3SvgContainer取决于c3返回的内容(抱歉,不熟悉库类型)