Reputation: 29
I want to be able to extend props A for a component for a wrapper component by adding a few more fields (props C). When I use a spread operator flow gives an error.
type A = {a: string}
type C = {b: number} & A //{b: number, a:string}
const c : C = {a: 'a', b: 1}
const {b, ...a} = c;
const a2 : A = a;
This gives an flow error 6: const a2 : A = a; ^ rest of object pattern.
Whats the way around this?
Upvotes: 1
Views: 901
Reputation: 2385
flow
has a lot of problems with spread operators, like you can see in the issues.
Best workaround at the moment is to explicitly extract each attribute, like Vivek Doshi said.
Upvotes: 0
Reputation: 58543
Here is the work around to it:
type A = {a: string}
type C = {b: number} & A //{b: number, a:string}
const c : C = {a: 'a', b: 1}
const {b, a} = c;
const a2 : A = {a};
Link to : FLOW
Upvotes: 2