File tree Expand file tree Collapse file tree 4 files changed +66
-2
lines changed Expand file tree Collapse file tree 4 files changed +66
-2
lines changed Original file line number Diff line number Diff line change @@ -1801,6 +1801,24 @@ Object {
1801
1801
}
1802
1802
`;
1803
1803
1804
+ exports[`main fixtures processes component "component_41.tsx" without errors 1`] = `
1805
+ Object {
1806
+ " description" : " " ,
1807
+ " displayName" : " MyComponent" ,
1808
+ " methods" : Array [],
1809
+ " props" : Object {
1810
+ " value" : Object {
1811
+ " description" : " String value of a number" ,
1812
+ " required" : false ,
1813
+ " tsType" : Object {
1814
+ " name" : " STRING_VALS[number]" ,
1815
+ " raw" : " typeof STRING_VALS[number]" ,
1816
+ },
1817
+ },
1818
+ },
1819
+ }
1820
+ `;
1821
+
1804
1822
exports[`main fixtures processes component "flow-export-type.js" without errors 1`] = `
1805
1823
Object {
1806
1824
" description" : " This is a Flow class component" ,
Original file line number Diff line number Diff line change
1
+ import React from 'react' ;
2
+
3
+ export const STRING_VALS = [
4
+ 'one' ,
5
+ 'two' ,
6
+ 'three'
7
+ ] ;
8
+
9
+ interface IProps {
10
+ /**
11
+ * String value of a number
12
+ */
13
+ value ?: typeof STRING_VALS [ number ] ;
14
+ }
15
+
16
+ const MyComponent = ( props : IProps ) => {
17
+ return (
18
+ < div >
19
+ { props . value }
20
+ </ div >
21
+ ) ;
22
+ }
23
+
24
+ export default MyComponent ;
Original file line number Diff line number Diff line change @@ -753,6 +753,26 @@ describe('getTSType', () => {
753
753
} ) ;
754
754
} ) ;
755
755
756
+ it ( 'resolves indexed access of array' , ( ) => {
757
+ const typePath = statement ( `
758
+ var x: typeof STRING_VALS[number];
759
+
760
+ const STRING_VALS = [
761
+ 'one',
762
+ 'two',
763
+ 'three'
764
+ ];
765
+ ` )
766
+ . get ( 'declarations' , 0 )
767
+ . get ( 'id' )
768
+ . get ( 'typeAnnotation' )
769
+ . get ( 'typeAnnotation' ) ;
770
+ expect ( getTSType ( typePath , null , noopImporter ) ) . toEqual ( {
771
+ name : 'STRING_VALS[number]' ,
772
+ raw : 'typeof STRING_VALS[number]' ,
773
+ } ) ;
774
+ } ) ;
775
+
756
776
it ( 'can resolve indexed access to imported type' , ( ) => {
757
777
const typePath = statement ( `
758
778
var x: A["x"] = 2;
Original file line number Diff line number Diff line change @@ -391,12 +391,14 @@ function handleTSIndexedAccessType(
391
391
// We only get the signature if the objectType is a type (vs interface)
392
392
if ( ! objectType . signature )
393
393
return {
394
- name : `${ objectType . name } [${ indexType . value . toString ( ) } ]` ,
394
+ name : `${ objectType . name } [${
395
+ indexType . value ? indexType . value . toString ( ) : indexType . name
396
+ } ]`,
395
397
raw : printValue ( path ) ,
396
398
} ;
397
399
const resolvedType = objectType . signature . properties . find ( p => {
398
400
// indexType.value = "'foo'"
399
- return p . key === indexType . value . replace ( / [ ' " ] + / g, '' ) ;
401
+ return indexType . value && p . key === indexType . value . replace ( / [ ' " ] + / g, '' ) ;
400
402
} ) ;
401
403
if ( ! resolvedType ) {
402
404
return { name : 'unknown' } ;
You can’t perform that action at this time.
0 commit comments