Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

when using rest operator flow requires optional object members to be returned. #6918

Open
acornejo opened this issue Sep 21, 2018 · 1 comment

Comments

@acornejo
Copy link

I have an object with an optional property. I have a function which receives an instance of said object and returns another instance whithout the optional property. Flow does not seem happy with this.

Example that reproduces issue:

https://flow.org/try/#0C4TwDgpgBAYg9nKBeKBvAUFKBDAXFAZ2ACcBLAOwHMAaTKAIwH59yBXAW3omNoF910AM1bkAxsFJxyUEtnIFBcYuwAUiuPnhwAlJoRo6oqUTT1qUAHRXiEIr2RR1Abjo3grYtJtEXvIA

type Foo = {
  a: string,
  b?: number,
}

function transform(foo: Foo): Foo {
  const {b, ...rest} = foo;
  return rest;
}
@wchargin
Copy link
Contributor

Closely related to #6863. Using return {...rest} suffices. Yes, Flow should be able to infer this type at rest-time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants