Permalink
Browse files

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 #8882

Differential Revision: D3587964

Pulled By: gabelevi

fbshipit-source-id: 629e0176484436848be69b1417638e1200a3669a
  • Loading branch information...
1 parent 5ee7041 commit 8eed600d5b2be78c405f7ef139a7b0e4a2480c85 @ide ide committed with Facebook Github Bot 2 Aug 15, 2016
Showing with 5 additions and 2 deletions.
  1. +5 −2 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<S: Styles> = {[key: $Keys<S>]: 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<T: Object, U>(obj: T): {[key:$Keys<T>]: number} {
- var result: T = (({}: any): T);
+ create<S: Styles>(obj: S): StyleSheet<S> {
+ const result: StyleSheet<S> = {};
for (var key in obj) {
StyleSheetValidation.validateStyle(key, obj);
result[key] = ReactNativePropRegistry.register(obj[key]);

0 comments on commit 8eed600

Please sign in to comment.