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 @@ -1577,3 +1577,21 @@ Object {
1577
1577
} ,
1578
1578
}
1579
1579
`;
1580
+
1581
+ exports[`main fixtures processes component "component_41.tsx" without errors 1`] = `
1582
+ Object {
1583
+ " description" : " " ,
1584
+ " displayName" : " MyComponent" ,
1585
+ " methods" : Array [],
1586
+ " props" : Object {
1587
+ " value" : Object {
1588
+ " description" : " String value of a number" ,
1589
+ " required" : false ,
1590
+ " tsType" : Object {
1591
+ " name" : " STRING_VALS[number]" ,
1592
+ " raw" : " typeof STRING_VALS[number]" ,
1593
+ },
1594
+ },
1595
+ },
1596
+ }
1597
+ `;
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 @@ -377,6 +377,26 @@ describe('getTSType', () => {
377
377
} ) ;
378
378
} ) ;
379
379
380
+ it ( 'resolves indexed access of array' , ( ) => {
381
+ const typePath = statement ( `
382
+ var x: typeof STRING_VALS[number];
383
+
384
+ const STRING_VALS = [
385
+ 'one',
386
+ 'two',
387
+ 'three'
388
+ ];
389
+ ` )
390
+ . get ( 'declarations' , 0 )
391
+ . get ( 'id' )
392
+ . get ( 'typeAnnotation' )
393
+ . get ( 'typeAnnotation' ) ;
394
+ expect ( getTSType ( typePath ) ) . toEqual ( {
395
+ name : 'STRING_VALS[number]' ,
396
+ raw : 'typeof STRING_VALS[number]' ,
397
+ } ) ;
398
+ } ) ;
399
+
380
400
it ( 'resolves types in scope' , ( ) => {
381
401
const typePath = statement ( `
382
402
var x: MyType = 2;
Original file line number Diff line number Diff line change @@ -365,12 +365,14 @@ function handleTSIndexedAccessType(
365
365
// We only get the signature if the objectType is a type (vs interface)
366
366
if (!objectType.signature)
367
367
return {
368
- name : `${ objectType . name } [${ indexType . value . toString ( ) } ]` ,
368
+ name : `${ objectType . name } [${
369
+ indexType . value ? indexType . value . toString ( ) : indexType . name
370
+ } ]`,
369
371
raw : printValue ( path ) ,
370
372
} ;
371
373
const resolvedType = objectType.signature.properties.find(p => {
372
374
// indexType.value = "'foo'"
373
- return p . key === indexType . value . replace ( / [ ' " ] + / g, '' ) ;
375
+ return indexType . value && p . key === indexType . value . replace ( / [ ' " ] + / g, '' ) ;
374
376
} );
375
377
if (!resolvedType) {
376
378
return { name : 'unknown' } ;
You can’t perform that action at this time.
0 commit comments