- Notifications
You must be signed in to change notification settings - Fork 4.3k
Closed
Labels
BASICBasic CheatsheetBasic Cheatsheet
Description
我想在可选属性上设置默认值,但是又不想在render 里给value 设默认值
const { value =5} = this.props
我找了很多方法,Partial也不行,以下是我代码
错误如下
import * as React from "react"; class App extends React.Component { public render() { return <A test={"a"} />; } } type AProps = { value?: number; [propName: string]: any; }; class A extends React.Component<AProps, any> { static defaultProps = { value: 5, }; public render() { const { value } = this.props; return <B value={value} />; } } type BProps = { value: number; }; class B extends React.Component<BProps, any> { public render() { const { value } = this.props; return <div>{value}</div>; } }
Metadata
Metadata
Assignees
Labels
BASICBasic CheatsheetBasic Cheatsheet