refactor: use Record type for objects

This commit is contained in:
satyajit.happy
2019-10-22 00:53:11 +02:00
parent 70f7e7a7c0
commit 2b5955efbe
12 changed files with 47 additions and 53 deletions

View File

@@ -42,7 +42,7 @@ type State = {
leftLabelLayout?: Layout;
};
const warnIfHeaderStylesDefined = (styles: { [key: string]: any }) => {
const warnIfHeaderStylesDefined = (styles: Record<string, any>) => {
Object.keys(styles).forEach(styleProp => {
const value = styles[styleProp];

View File

@@ -65,7 +65,7 @@ type State = {
scenes: Scene<Route<string>>[];
progress: ProgressValues;
layout: Layout;
floatingHeaderHeights: { [key: string]: number };
floatingHeaderHeights: Record<string, number>;
};
const dimensions = Dimensions.get('window');
@@ -119,23 +119,20 @@ const getFloatingHeaderHeights = (
insets: EdgeInsets,
descriptors: StackDescriptorMap,
layout: Layout,
previous: { [key: string]: number }
previous: Record<string, number>
) => {
const defaultHeaderHeight = getDefaultHeaderHeight(layout, insets);
return routes.reduce(
(acc, curr) => {
const { options = {} } = descriptors[curr.key] || {};
const { height = previous[curr.key] } = StyleSheet.flatten(
options.headerStyle || {}
);
return routes.reduce<Record<string, number>>((acc, curr) => {
const { options = {} } = descriptors[curr.key] || {};
const { height = previous[curr.key] } = StyleSheet.flatten(
options.headerStyle || {}
);
acc[curr.key] = typeof height === 'number' ? height : defaultHeaderHeight;
acc[curr.key] = typeof height === 'number' ? height : defaultHeaderHeight;
return acc;
},
{} as { [key: string]: number }
);
return acc;
}, {});
};
export default class Stack extends React.Component<Props, State> {