Skip to content

Commit 8eed600

Browse files
ideFacebook Github Bot 2
authored andcommitted
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
1 parent 5ee7041 commit 8eed600

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

Libraries/StyleSheet/StyleSheet.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ var StyleSheetValidation = require('StyleSheetValidation');
1717

1818
var flatten = require('flattenStyle');
1919

20+
export type Styles = {[key: string]: Object};
21+
export type StyleSheet<S: Styles> = {[key: $Keys<S>]: number};
22+
2023
var hairlineWidth = PixelRatio.roundToNearestPixel(0.4);
2124
if (hairlineWidth === 0) {
2225
hairlineWidth = 1 / PixelRatio.get();
@@ -160,8 +163,8 @@ module.exports = {
160163
/**
161164
* Creates a StyleSheet style reference from the given object.
162165
*/
163-
create<T: Object, U>(obj: T): {[key:$Keys<T>]: number} {
164-
var result: T = (({}: any): T);
166+
create<S: Styles>(obj: S): StyleSheet<S> {
167+
const result: StyleSheet<S> = {};
165168
for (var key in obj) {
166169
StyleSheetValidation.validateStyle(key, obj);
167170
result[key] = ReactNativePropRegistry.register(obj[key]);

0 commit comments

Comments
 (0)