I just added Flow to my Create-React-App project, and while converting some of my calculation code to flow-typed, I encountered this error with a destructured "object as params"
Original sig:
calcWeightOnConveyor({ tonsPerHour, conveyorLength, conveyorSpeed })
After flow-type:
calcWeightOnConveyor({ tonsPerHour: number, conveyorLength: number, conveyorSpeed: number }): number
And the error:
$ flow
Error: src/utils/vortex/calculate.js:31
31: export function calcWeightOnConveyor({ tonsPerHour: number, conveyorLength: number, conveyorSpeed: number }) {
^^^^^^ Strict mode function may not have duplicate parameter names
Is there a way to use flow with object destructuring in this way or should I redesign these function APIs?
Effective May 5, 2020 the Dynamics 365 connector used for data integrations, flows, Azure Logic Apps, and canvas apps is officially deprecated.
Destructuring is a JavaScript expression that allows us to extract data from arrays, objects, and maps and set them into new, distinct variables. Destructuring allows us to extract multiple properties, or items, from an array at a time.
When destructuring the objects, we use keys as the name of the variable. The variable name must match the property (or keys) name of the object. If it does not match, then it receives an undefined value. This is how JavaScript knows which property of the object we want to assign.
JavaScript Object Destructuring is the syntax for extracting values from an object property and assigning them to a variable. The destructuring is also possible for JavaScript Arrays.
Generally the pattern I follow, especially for functional components props is as follows:
type Props = {
prop: Type,
};
const Component = ({
prop,
}: Props) => ();
Yes you can do so by annotating the entire object like the following:
calcWeightOnConveyor({
tonsPerHour,
conveyorLength,
conveyorSpeed
}: {
tonsPerHour:number,
conveyorLength:number,
conveyorSpeed:number
}):number
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With