File tree Expand file tree Collapse file tree 2 files changed +14
-0
lines changed Expand file tree Collapse file tree 2 files changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -68,6 +68,11 @@ describe('getFlowType', () => {
68
68
expect ( getFlowType ( typePath ) ) . toEqual ( { name : 'xyz' , nullable : true } ) ;
69
69
} ) ;
70
70
71
+ it ( 'detects array type shorthand' , ( ) => {
72
+ var typePath = expression ( 'x: number[]' ) . get ( 'typeAnnotation' ) . get ( 'typeAnnotation' ) ;
73
+ expect ( getFlowType ( typePath ) ) . toEqual ( { name : 'Array' , elements : [ { name : 'number' } ] , raw : 'number[]' } ) ;
74
+ } ) ;
75
+
71
76
it ( 'detects array type' , ( ) => {
72
77
var typePath = expression ( 'x: Array<number>' ) . get ( 'typeAnnotation' ) . get ( 'typeAnnotation' ) ;
73
78
expect ( getFlowType ( typePath ) ) . toEqual ( { name : 'Array' , elements : [ { name : 'number' } ] , raw : 'Array<number>' } ) ;
Original file line number Diff line number Diff line change @@ -37,6 +37,7 @@ const flowLiteralTypes = {
37
37
} ;
38
38
39
39
const namedTypes = {
40
+ ArrayTypeAnnotation : handleArrayTypeAnnotation ,
40
41
GenericTypeAnnotation : handleGenericTypeAnnotation ,
41
42
ObjectTypeAnnotation : handleObjectTypeAnnotation ,
42
43
UnionTypeAnnotation : handleUnionTypeAnnotation ,
@@ -76,6 +77,14 @@ function handleKeysHelper(path: NodePath) {
76
77
}
77
78
}
78
79
80
+ function handleArrayTypeAnnotation ( path : NodePath ) {
81
+ return {
82
+ name : 'Array' ,
83
+ elements : [ getFlowType ( path . get ( 'elementType' ) ) ] ,
84
+ raw : printValue ( path ) ,
85
+ } ;
86
+ }
87
+
79
88
function handleGenericTypeAnnotation ( path : NodePath ) {
80
89
if ( path . node . id . name === '$Keys' && path . node . typeParameters ) {
81
90
return handleKeysHelper ( path ) ;
You can’t perform that action at this time.
0 commit comments