反応プロジェクトに Typescript を使用しています。したがって、コンストラクターで小道具を渡しています。コンストラクターの「小道具」を壊して、それをクラスレベルの変数に割り当てたい。
これは私のコードです -
abstract class IProps{
abstract type:'text'|'checkbox'|'radio';
abstract value?: any;
abstract name?: string;
abstract id?:string;
abstract onClick?: ((event: React.MouseEvent<HTMLInputElement, MouseEvent>) => void);
abstract onChange?:((val: any) => void);
abstract classnames: string;
abstract placeholder?: any;
}
interface InputProps extends IProps{
isvalid?: boolean;
}
export class Input extends Component<InputProps>{
isvalid: boolean|undefined=true;
iProps: IProps|null = null;
constructor(props: InputProps){
super(props);
console.log(this.props);
const {isvalid, ...iProps} = this.props;
this.isvalid = isvalid;
this.iProps = iProps;
}
}
コンストラクターのこれらのステートメントは私にとってはうまくいきます。
const {isvalid, ...iProps} = this.props;
this.isvalid = isvalid;
this.iProps = iProps;
const
しかし、ステートメントを使用せずに値を割り当てたいです。私はこのようなことをしたい -
{isvalid: this.isvalid, ...iProps: this.iProps} = this.props;
このような値を割り当てる方法は?