Skip to content

Commit

Permalink
[Flow] Define Flow types for style and stylesheet objects, more checking
Browse files Browse the repository at this point in the history
- 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

Test Plan: `flow`
  • Loading branch information
ide committed Jul 19, 2016
1 parent a564af8 commit 276ece9
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions Libraries/StyleSheet/StyleSheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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> {
let result: StyleSheet<S> = {};
for (var key in obj) {
StyleSheetValidation.validateStyle(key, obj);
result[key] = ReactNativePropRegistry.register(obj[key]);
Expand Down

0 comments on commit 276ece9

Please sign in to comment.