【发布时间】:2017-11-30 12:47:01
【问题描述】:
我有以下代码
type SetupProps = {
defaults: string;
}
export class Setup extends React.Component<SetupProps, SetupState> {
constructor(props: any) {
super(props);
this.props.defaults = "Whatever";
}
当尝试运行此代码时,TS 编译器返回以下错误:
无法分配给“默认值”,因为它是常量或只读的 属性。
deafualts 是一个只读属性,它显然没有以这种方式标记。
【问题讨论】:
标签: javascript reactjs typescript readonly