Issue
In the following piece of typescript code I don't understand why the data parameter is between curly brackets and why it has a : followed by the same data object with a type specification. What does this mean?
addArrivingTruckSuggestions(state: ITruckState, { data }: { data: IOperationalTruck[] }) {
state.arrivingTruckSuggestions = searchService.createTruckSuggestions(data);
}
Solution
This function has two parameters, state, and an object containing data.
The state object has a type of ITruckState. Straight forward enough.
The next parameter must be an object, but the only property this function cares about is data. This is why there are curly braces around data, it is being destructured from the wrapper object that is passed in. The second set of curly braces is to define datas type. It is wrapped in curly braces because only the data property is given a type.
Answered By - Michael Cleary
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.