Last active
July 21, 2018 02:37
-
-
Save zrod/748323bcff5b5e3874fc366a2b2a9732 to your computer and use it in GitHub Desktop.
property X is read-only in CategoryType [1] but writable in object type [2] in array element.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// @flow | |
export type CategoryType = { | |
+id: number, | |
+name: string, | |
+slug: string, | |
+description: string | |
}; | |
// ... | |
const categoriesItems = state.categories.items.slice(); | |
return { | |
categories: formatCollectionForDropdown(categoriesItems) | |
}; | |
// ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** @flow */ | |
export function formatCollectionForDropdown( | |
collection: Array<{ | |
id: number, | |
slug: string, | |
name: string, | |
description: string | |
}> | |
): Array<{ | |
key: number, | |
slug: string, | |
text: string, | |
value: number | |
}> { | |
return collection.map( | |
( | |
item: { | |
id: number, | |
slug: string, | |
name: string | |
} | |
): { | |
key: number, | |
slug: string, | |
text: string, | |
value: number | |
} => { | |
return { | |
key: item.id, | |
slug: item.slug, | |
text: item.name, | |
value: item.id | |
}; | |
} | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment