다음 항목이 있습니다.
export interface Tool {
label: string;
visible?: boolean;
icon?: string;
devider?: boolean;
onClick: () => void;
}
this.controls = [
{
label: 'Перемещение',
visible: true,
icon: 'fas fa-arrows-alt fa-fw fa-lg mr-2',
onClick: () => {
this.dispatch(this.activateMoveAction.bind(this), this);
},
}];
그리고 dispather :
dispatch(dispatcher: Function, control: Tool) {}
줄에이 오류가 발생하는 이유 : .bind(this),
this );
Argument of type 'this' is not assignable to parameter of type 'Tool'.
이것은 내 문제를 해결하지만 끔찍하게 보입니다.
this.dispatch(this.activateMoveAction.bind(this), this.controls[0]);
이것은 컨텍스트를 보존하는 화살표 기능을 사용하기 때문에 발생합니다 (this). 일반 함수를 사용하면 올바른 컨텍스트를 갖게됩니다.
화살표 기능에 대한 자세한 내용은 https://2ality.com/2012/04/arrow-functions.html에서 확인할 수 있습니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다