Skip to content

Instantly share code, notes, and snippets.

@zrod
Last active July 21, 2018 02:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zrod/748323bcff5b5e3874fc366a2b2a9732 to your computer and use it in GitHub Desktop.
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.
// @flow
export type CategoryType = {
+id: number,
+name: string,
+slug: string,
+description: string
};
// ...
const categoriesItems = state.categories.items.slice();
return {
categories: formatCollectionForDropdown(categoriesItems)
};
// ...
/** @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