Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are those curly brackets within a function definition parameter?

I have an Angular 5 project and I saw this Typescript code.

(method) CreateFlightComponent.handleSave({ currentValue, stepIndex }: {
    currentValue: Partial<Flight>;
    stepIndex: number;
}): void

Could anyone explain this part? Or is there any better way to express with a different syntax?

{ currentValue, stepIndex }: {
    currentValue: Partial<Flight>;
    stepIndex: number;
} 
like image 693
knowledgeseeker Avatar asked Nov 01 '25 04:11

knowledgeseeker


1 Answers

Well, the handleSave function takes a complex type as input parameter, and returns void. The input type contains two properties:

  • currentValue is of type Partial<Flight>
  • stepIndex is of type number.

Another way to express the same with a different syntax could be:

interface IHandleTypeParams {
    currentValue: Partial<Flight>;
    stepIndex: number;
}

and then use the interface instead:

CreateFlightComponent.handleSave( input:IHandleTypeParams): void

or with destructuring:

CreateFlightComponent.handleSave({ currentValue, stepIndex }: IHandleTypeParams): void

See the playground.

Read more about destructuring on the MDN.

like image 73
MikNiller Avatar answered Nov 03 '25 02:11

MikNiller



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!