Reactjs ';这';隐式具有类型';任何';因为它没有类型注释。在函数上调用bind时

Reactjs ';这';隐式具有类型';任何';因为它没有类型注释。在函数上调用bind时,reactjs,typescript,Reactjs,Typescript,代码: 这应该是什么类型的?实际上我不知道。我不会使用这个。我只想通过部分.rows 编辑:这是组件的完整代码,它包含上面的部分,但也包含其他代码 [ts] 'this' implicitly has type 'any' because it does not have a type annotation. import*as React from'React'; 导入“/TechSpec.css”; 接口部分{ 标题:字符串; 行:第[]行; } 接口行{ 标签:字符串; 值:字符串[];

代码:

这应该是什么类型的?实际上我不知道。我不会使用
这个
。我只想通过
部分.rows

编辑:这是组件的完整代码,它包含上面的部分,但也包含其他代码

[ts] 'this' implicitly has type 'any' because it does not have a type annotation.
import*as React from'React';
导入“/TechSpec.css”;
接口部分{
标题:字符串;
行:第[]行;
}
接口行{
标签:字符串;
值:字符串[];
}
常量techSpecTableData={
...
};
const renderRows=((行:行[])=>{
返回(
...
);
});
const renderSections=techSpecTableData.sections.map((节:节,索引:编号)=>{
返回(
{节.标题}
{renderRows.bind(this,section.rows)}
);
});
const renderhadings=techSpecTableData.headings.map((heading:string,index:number)=>{
返回(
{标题}
);
});
常量TechSpec=()=>{
返回(
技术规格
{renderhadings}
{renderSections}
);
};
导出默认TechSpec;

正如您所使用的,它很可能只是
窗口
。TypeScript可能不知道这件事。此外,您很可能不想使用它。只需
renderRows(section.rows)
就可以了

但是,我建议您使用组件,而不是使用
renderX
函数。这应该很容易做到,因为您已经有了这些函数——到功能组件的转换应该非常小

import * as React from 'react';
import './TechSpec.css';

interface Section {
    heading: string;
    rows: Row[];
}

interface Row {
    label: string;
    values: string[];
}

const techSpecTableData = {
    ...
};

const renderRows = ((rows: Row[]) => {
    return (
        <div key={index}>
            ...
        </div>
    );
});

const renderSections = techSpecTableData.sections.map((section: Section, index: number) => {
    return (
        <div key={index} className="tech-spec-table-section">
            <div className="tech-spec-table-section__heading">{section.heading}</div>
            {renderRows.bind(this, section.rows)}
        </div>
    );
});

const renderHeadings = techSpecTableData.headings.map((heading: string, index: number) => {
    return (
        <div key={index} className="tech-spec-table__header__heading">
            {heading}
        </div>
    );
});

const TechSpec = () => {
    return (
        <div className="tech-spec">
            <div className="content-container">
                <h2 className="heding--h2 heading--emphasized">
                    Technical Specification
                </h2>

                <div className="tech-spec-table__header">
                    {renderHeadings}
                </div>
                <div className="tech-spec-table__sections">
                    {renderSections}
                </div>
            </div>
        </div>
    );
};

export default TechSpec;
const Section=({Section})=>(
…行内容。。。
);
常量节=({Sections})=>
图((节,索引)=>);
常量TechSpec=()=>(
...
...
);

注意,如果可能的话,我会使用
key={section.id}
或类似的东西,而不是
key={index}

您不需要使用
renderRows.bind
。你能告诉我们更多的情况吗?i、 e.
const renderSections
在代码中的什么位置?@ExplosionPills:它在功能组件中。它是在JSX内部的函数组件的返回函数中用{renderSections}@ExplosionPills调用的。我已经编辑了这篇文章来添加Context。我认为您应该使用bind的唯一用法是事件处理程序……如果您知道更好的方法,欢迎您回答。我只想将行数据发送到另一个负责渲染的函数,这样每个renderPart函数就不会变得太大。否则,我感谢你的指导,并将谷歌如何做到这一点,明天。谢谢
import * as React from 'react';
import './TechSpec.css';

interface Section {
    heading: string;
    rows: Row[];
}

interface Row {
    label: string;
    values: string[];
}

const techSpecTableData = {
    ...
};

const renderRows = ((rows: Row[]) => {
    return (
        <div key={index}>
            ...
        </div>
    );
});

const renderSections = techSpecTableData.sections.map((section: Section, index: number) => {
    return (
        <div key={index} className="tech-spec-table-section">
            <div className="tech-spec-table-section__heading">{section.heading}</div>
            {renderRows.bind(this, section.rows)}
        </div>
    );
});

const renderHeadings = techSpecTableData.headings.map((heading: string, index: number) => {
    return (
        <div key={index} className="tech-spec-table__header__heading">
            {heading}
        </div>
    );
});

const TechSpec = () => {
    return (
        <div className="tech-spec">
            <div className="content-container">
                <h2 className="heding--h2 heading--emphasized">
                    Technical Specification
                </h2>

                <div className="tech-spec-table__header">
                    {renderHeadings}
                </div>
                <div className="tech-spec-table__sections">
                    {renderSections}
                </div>
            </div>
        </div>
    );
};

export default TechSpec;
const Section = ({ section }) => (
  <div>
    ... row content ...
  </div>
);

const Sections = ({ sections }) =>
  sections.map((section, index) => <Section section={section} key={index} />);

const TechSpec = () => (
  ...
  <div className="tech-spec-table__sections">
    <Sections sections={techSpecTableData.section} />
  </div>
  ...
);