Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
How to make return type dependent on child type? #6897
I have a function that can take either of two types, and depending on the type of the argument, it returns a specific type. Is there an appropriate syntax for this? Something like:
Usually, for function, you want to use the intersection
So this would give something like that.
You'll observe that added exact types, and made the arrays read-only, without that, you'll get more errors.
However, I still do have errors here, and I'm not sure about how to fix them^^ But the types of the function are correct, flow struggles with its implementation. So that would let you put a $FlowFixMe at the implementation, while still getting your call-sites typechecked.