React + TypeScript 错误:没有与此调用匹配的重载
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/58449813/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
React + TypeScript error: No overload matches this call
提问by Petar Ivcec
I am receiving a massive error when mapping through an array like:
通过数组映射时,我收到一个巨大的错误,例如:
// Home.tsx
render() {
const { inputs, outputs, expectedOutputs } = this.state;
return (
<ContentContainer>
{inputs.map((input, i) => {
return (
<TestRow
key={i}
rowNumber={i}
xml={inputs[i].xml}
desc={inputs[i].desc}
output={outputs[i]}
expectedOutput={expectedOutputs[i]}
handleTextAreaUpdate={this.handleTextAreaUpdate}
/>
);
})}
</ContentContainer>
);
// TestRow.tsx
interface TestRowProps {
xml: string;
desc: string;
output: string;
expectedOutput: string;
rowNumber: number;
}
class TestRow extends Component<TestRowProps, {}> {
textArea: any;
the error is:
错误是:
No overload matches this call. Overload 1 of 2, '(props: Readonly): TestRow', gave the following error.
没有过载匹配此调用。重载 1 of 2, '(props: Readonly): TestRow',出现以下错误。
Type '{ key: number; rowNumber: number; xml: string; desc: string; output: never; expectedOutput: string; handleTextAreaUpdate: (e: { target: { value: string; }; }, column: number, rowNumber: number) => void; }' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes<TestRow> & Readonly<TestRowProps> & Readonly<{ children?: ReactNode; }>'.
Property 'handleTextAreaUpdate' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes<TestRow> & Readonly<TestRowProps> & Readonly<{ children?: ReactNode; }>'.
Overload 2 of 2, '(props: TestRowProps, context?: any): TestRow', gave the following error.
Type '{ key: number; rowNumber: number; xml: string; desc: string; output: never; expectedOutput: string; handleTextAreaUpdate: (e: { target: { value: string; }; }, column: number, rowNumber: number) => void; }' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes<TestRow> & Readonly<TestRowProps> & Readonly<{ children?: ReactNode; }>'.
Property 'handleTextAreaUpdate' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes<TestRow> & Readonly<DiagramProps> & Readonly<{ children?: ReactNode; }>'
. TS2769
. TS2769
采纳答案by SlashArash
in the error message, you can find the problem. Property 'handleTextAreaUpdate' does not exist on type
means that you should define a property for handleTextAreaUpdate
in the TestRowProps
interface.
在错误信息中,您可以找到问题所在。Property 'handleTextAreaUpdate' does not exist on type
意味着您应该handleTextAreaUpdate
在TestRowProps
接口中定义一个属性。