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

Flow: fix errors in 'flatMap.js' on old Flow versions #2137

Merged
merged 1 commit into from Aug 27, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/polyfills/flatMap.js
Expand Up @@ -5,11 +5,14 @@ declare function flatMap<T, U>(
fn: (item: T, index: number) => $ReadOnlyArray<U> | U,
): Array<U>;

// Workaround to make older Flow versions happy
const flatMapMethod = (Array.prototype: any).flatMap;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jedwards1211 We enabled Flow warnings in config:

include_warnings=true

So flow generate warnings for ignored $FlowFixMe.
It also possible that other projects using include_warnings=true
So I decided to just use any since it works in all Flow versions.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha, yeah the fact that ignore comments may not work when the package is used as a dependency is a real shortcoming of Flow right now

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I released 14.5.4 📦 with this fix included.
Sorry for the delay.


/* eslint-disable no-redeclare */
// $FlowFixMe
const flatMap = Array.prototype.flatMap
const flatMap = flatMapMethod
? function(list, fn) {
return Array.prototype.flatMap.call(list, fn);
return flatMapMethod.call(list, fn);
}
: function(list, fn) {
let result = [];
Expand Down