facebook / flow

Adds static typing to JavaScript to improve developer productivity and code quality.
https://flow.org/
MIT License
22.07k stars 1.85k forks source link

Allow for methods that throw exceptions to work as predicate functions. #5049

Open newtang opened 6 years ago

newtang commented 6 years ago

In the example below doMoreStuff() is guaranteed to have string arguments, because checkArgs will throw otherwise.

https://flow.org/try/#0PTACDMBsHsHcCgBEBXAzgUwASoC4CcBLAYx0QG555xkA7Eg6GzAE2gGUdlxwAKNdPAElmALgD8uQjQDmAGkzoAbuho5h4yQRkBKAN7wAkAaIALdEQDWAQTzTUfDEObylKtc20UjrALLQ86BxcvPxOLsqqwp7wAL6U1HQ4DEy+-oGc3A4C6poy4W45+FrSevCYmESMqNCQ6AB0MNJZYQoR7tFxVLT0jBVmljZ2zcL5kR4iitAEzJgApKbmFqj6BgS8AIShUSsGOCZ4cJg06LCYAKJ4B3g8iABCAIYzwojRBp2rG65jpUZ7B6fHU4XK43B4zL6kV5xGJAA

jcready commented 6 years ago

Predicates need to return booleans: try this

newtang commented 6 years ago

@jcready If it's a requirement that Predicates need to return booleans, would it be possible for Flow to allow throws in the function before the return statement like this example