Skip to content
This repository has been archived by the owner on Jul 21, 2021. It is now read-only.

Commit

Permalink
Fix flow errors and ignore flow false positives
Browse files Browse the repository at this point in the history
See facebook/flow#2221 for false positives
regarding Object.values
  • Loading branch information
jacobmischka committed Sep 14, 2017
1 parent 429eb45 commit 53ff8c3
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions resources/assets/js/modules/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import striptags from 'striptags';

import type { DateLike } from './date-utils.js';

// All the $FlowFixMes in this file are due to
// https://github.com/facebook/flow/issues/2221

type DateString = string;

// FIXME
Expand Down Expand Up @@ -242,15 +245,15 @@ export function groupMilestones(milestones: Array<Milestone>): Array<Select2OptG
groupTitle += ` — ${milestone.training_level}`;

if (!milestoneGroups[groupTitle])
milestoneGroups[groupTitle] = ({
milestoneGroups[groupTitle] = {
text: groupTitle,
children: []
}: Select2OptGroup);
};

milestoneGroups[groupTitle].children.push(({
milestoneGroups[groupTitle].children.push({
id: milestone.id.toString(),
text: milestone.title
}: Select2Option));
});
}
for(let groupTitle in milestoneGroups) {
let milestoneGroup = milestoneGroups[groupTitle];
Expand All @@ -264,10 +267,11 @@ export function groupMilestones(milestones: Array<Milestone>): Array<Select2OptG
});
}

return Object.values(milestoneGroups);
// $FlowFixMe
return (Object.values(milestoneGroups): Array<Select2OptGroup>);
}

export function fetchUserGroups(): Promise<Array<User>> {
export function fetchUserGroups(): Promise<Array<Select2OptGroup>> {
return fetchUsers().then(groupUsers);
}

Expand Down Expand Up @@ -342,6 +346,7 @@ export function groupUsers(users: Array<User>): Array<Select2OptGroup> {
}
});

// $FlowFixMe
let groupedUsers: Array<Select2OptGroup> = Object.values(groups);
for (let group: Select2OptGroup of groupedUsers) {
group.children.sort(sortSelect2Objects);
Expand All @@ -358,7 +363,7 @@ export function fetchForms(): Promise<Array<Form>> {
}).then(response => response.json());
}

export function fetchFormGroups(): Promise<Array<Select2Option>> {
export function fetchFormGroups(): Promise<Array<Select2OptGroup>> {
return fetchForms().then(groupForms);
}

Expand All @@ -381,6 +386,7 @@ export function groupForms(forms: Array<Form>): Array<Select2OptGroup> {
}
});

// $FlowFixMe
let groupedForms: Array<Select2OptGroup> = Object.values(groups);
for (let group: Select2OptGroup of groupedForms) {
group.children.sort(sortSelect2Objects);
Expand Down

0 comments on commit 53ff8c3

Please sign in to comment.