File tree Expand file tree Collapse file tree 2 files changed +87
-5
lines changed Expand file tree Collapse file tree 2 files changed +87
-5
lines changed Original file line number Diff line number Diff line change @@ -272,12 +272,12 @@ module.exports = {
272
272
* array, saving allocations and maintaining reference equality for
273
273
* PureComponent checks.
274
274
*/
275
- compose (
276
- style1 : ?DangerouslyImpreciseStyleProp ,
277
- style2 : ?DangerouslyImpreciseStyleProp ,
278
- ) : ?DangerouslyImpreciseStyleProp {
275
+ compose < T : DangerouslyImpreciseStyleProp > (
276
+ style1 : ?T ,
277
+ style2 : ?T ,
278
+ ) : ?T | $ReadOnlyArray < T > {
279
279
if ( style1 != null && style2 != null ) {
280
- return [ style1 , style2 ] ;
280
+ return ( [ style1 , style2 ] : $ReadOnlyArray < T > ) ;
281
281
} else {
282
282
return style1 != null ? style1 : style2 ;
283
283
}
Original file line number Diff line number Diff line change
1
+ /**
2
+ * Copyright (c) 2015-present, Facebook, Inc.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @flow strict-local
8
+ * @format
9
+ */
10
+
11
+ 'use strict' ;
12
+
13
+ const StyleSheet = require ( 'StyleSheet' ) ;
14
+
15
+ import type { ImageStyleProp , TextStyleProp } from 'StyleSheet' ;
16
+
17
+ const imageStyle = { tintColor : 'rgb(0, 0, 0)' } ;
18
+ const textStyle = { color : 'rgb(0, 0, 0)' } ;
19
+
20
+ module . exports = {
21
+ testGoodCompose ( ) {
22
+ ( StyleSheet . compose (
23
+ imageStyle ,
24
+ imageStyle ,
25
+ ) : ImageStyleProp ) ;
26
+
27
+ ( StyleSheet . compose (
28
+ textStyle ,
29
+ textStyle ,
30
+ ) : TextStyleProp ) ;
31
+
32
+ ( StyleSheet . compose (
33
+ null ,
34
+ null ,
35
+ ) : TextStyleProp ) ;
36
+
37
+ ( StyleSheet . compose (
38
+ textStyle ,
39
+ null ,
40
+ ) : TextStyleProp ) ;
41
+
42
+ ( StyleSheet . compose (
43
+ textStyle ,
44
+ Math . random ( ) < 0.5 ? textStyle : null ,
45
+ ) : TextStyleProp ) ;
46
+
47
+ ( StyleSheet . compose (
48
+ [ textStyle ] ,
49
+ null ,
50
+ ) : TextStyleProp ) ;
51
+
52
+ ( StyleSheet . compose (
53
+ [ textStyle ] ,
54
+ null ,
55
+ ) : TextStyleProp ) ;
56
+
57
+ ( StyleSheet . compose (
58
+ [ textStyle ] ,
59
+ [ textStyle ] ,
60
+ ) : TextStyleProp ) ;
61
+ } ,
62
+
63
+ testBadCompose ( ) {
64
+ // $FlowExpectedError - Incompatible type.
65
+ ( StyleSheet . compose (
66
+ textStyle ,
67
+ textStyle ,
68
+ ) : ImageStyleProp ) ;
69
+
70
+ ( StyleSheet . compose (
71
+ // $FlowExpectedError - Incompatible type.
72
+ [ textStyle ] ,
73
+ null ,
74
+ ) : ImageStyleProp ) ;
75
+
76
+ // $FlowExpectedError - Incompatible type.
77
+ ( StyleSheet . compose (
78
+ Math . random ( ) < 0.5 ? textStyle : null ,
79
+ null ,
80
+ ) : ImageStyleProp ) ;
81
+ } ,
82
+ } ;
You can’t perform that action at this time.
0 commit comments