我有一个Angular 5项目,我看到了这个Typescript代码。
(method) CreateFlightComponent.handleSave({ currentValue, stepIndex }: {
currentValue: Partial<Flight>;
stepIndex: number;
}): void
有人可以解释这部分吗?还是有更好的方法来表达不同的语法?
{ currentValue, stepIndex }: {
currentValue: Partial<Flight>;
stepIndex: number;
}
答案 0 :(得分:1)
好吧,handleSave
函数将复杂类型作为输入参数,并返回void。输入类型包含两个属性:
currentValue
的类型为Partial<Flight>
stepIndex
的类型为number
。另一种使用不同语法表示相同内容的方法可能是:
interface IHandleTypeParams {
currentValue: Partial<Flight>;
stepIndex: number;
}
,然后改为使用界面:
CreateFlightComponent.handleSave( input:IHandleTypeParams): void
或具有破坏性:
CreateFlightComponent.handleSave({ currentValue, stepIndex }: IHandleTypeParams): void
请参见playground。
了解有关在MDN上进行销毁的更多信息。