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

Cannot call ... because an indexer property is missing in ... #7191

Closed
steida opened this issue Nov 18, 2018 · 1 comment
Closed

Cannot call ... because an indexer property is missing in ... #7191

steida opened this issue Nov 18, 2018 · 1 comment

Comments

@steida
Copy link

steida commented Nov 18, 2018

Just spend the whole day trying to figure out why simple Flow generic code does not work.

Leaving it here, in order to help the future me or anyone else.

Flow cannot say in humanly comprehensible language that generic type needs to be bounded. https://flow.org/en/docs/types/generics/#toc-generic-types-act-as-bounds

Still, don't understand why Flow needs it and what actually fixes it.

@steida
Copy link
Author

steida commented Nov 18, 2018

: Object!

export default function useMutation<Mutation: Object, Name>(
  config: Config,
  validate?: (Input<Mutation>) => Errors<Mutation, Name>,
): [Commit<Mutation>, Errors<Mutation, Name>] {
  const [errors, setErrors] = useState<Errors<Mutation, Name>>(null);
  const environment = useRelayEnvironment();
  function commit(input) {
    if (validate) {
      const errors = validate(input);
      setErrors(errors);
    }
  }
  return [commit, errors];
}

@steida steida closed this as completed Nov 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant