-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
validation method like isString
doesn't work when used in other methods having mixed arguments
#7318
Comments
function isString (thing: mixed): boolean %checks {
return typeof thing === 'string';
} Even using this special
Anther trick or hack that you can do is to write actual JS code, e.g. a function, in that Flow comment style. Flow will parse it as if it's part of the code, but the JS runtime will of course ignore it, since it's a comment. This feature can be used for all kinds of tricks (to get Flow to understand something), your imagination is the limit, without polluting your actual executable code.. Here's a Flow Try illustrating the Note that I have to use a function if I have that |
Thanks a lot @lll000111. I did try to search open/closed issues (even googled it) before raising this issue, but I missed proper keywords for my search, thus couldn't find any solutions. Found that this feature is Documented as Predicate Functions, related to #4723 |
The docs don't mention the Flow comment syntax or the |
Issue Code Example on
/try
foo()
method above throws flow-type compilation errors Cannot callgetCustom
withx
bound tostring
becauseCustom
[1] is incompatible with string [2], thoughisString
method validatesx
before any conversionsAbove code works fine, if I replace
isString(x)
, with it's definition:The text was updated successfully, but these errors were encountered: