传递数字类型作为React组件属性

ale*_*exb 1 reactjs asp.net-core-2.0

我刚刚在asp.net core 2.0(React项目类型)上开始使用React。将数字类型传递到组件时遇到麻烦。例如,如果我尝试传递数字类型(id),则会收到错误消息:

TS)类型'{id:boolean;}'不可分配给类型'IntrinsicAttributes&IntrinsicClassAttributes ...

import * as React from 'react';
interface HelloWorldProps{
  name: string
  id: number
}
export class Greeting extends React.Component<HelloWorldProps, any> {
  render() {
      return <h1>Hello, {this.props.name}</h1>;
  }
}
export default Greeting;
Run Code Online (Sandbox Code Playgroud)

当我尝试渲染组件时,在这里出现TS错误...

<HelloWorld id=1 />
Run Code Online (Sandbox Code Playgroud)

没有id属性,它可以正常工作。

amy*_*yst 7

您应将数字值括在大括号中,如下所示-