From 8eed600d5b2be78c405f7ef139a7b0e4a2480c85 Mon Sep 17 00:00:00 2001 From: James Ide Date: Mon, 15 Aug 2016 10:37:29 -0700 Subject: [PATCH] Define Flow types for style and stylesheet objects, more checking Summary: - Define a Styles type for the object that gets passed into StyleSheet.create - Define a StyleSheet type that is returned from StyleSheet.create - Clean up the type declarations in StyleSheet.create Closes https://github.com/facebook/react-native/pull/8882 Differential Revision: D3587964 Pulled By: gabelevi fbshipit-source-id: 629e0176484436848be69b1417638e1200a3669a --- Libraries/StyleSheet/StyleSheet.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Libraries/StyleSheet/StyleSheet.js b/Libraries/StyleSheet/StyleSheet.js index c9eab42c4bb..e4f767f9e15 100644 --- a/Libraries/StyleSheet/StyleSheet.js +++ b/Libraries/StyleSheet/StyleSheet.js @@ -17,6 +17,9 @@ var StyleSheetValidation = require('StyleSheetValidation'); var flatten = require('flattenStyle'); +export type Styles = {[key: string]: Object}; +export type StyleSheet = {[key: $Keys]: number}; + var hairlineWidth = PixelRatio.roundToNearestPixel(0.4); if (hairlineWidth === 0) { hairlineWidth = 1 / PixelRatio.get(); @@ -160,8 +163,8 @@ module.exports = { /** * Creates a StyleSheet style reference from the given object. */ - create(obj: T): {[key:$Keys]: number} { - var result: T = (({}: any): T); + create(obj: S): StyleSheet { + const result: StyleSheet = {}; for (var key in obj) { StyleSheetValidation.validateStyle(key, obj); result[key] = ReactNativePropRegistry.register(obj[key]);