@@ -19,6 +19,7 @@ import getTypeParameters, {
1919import type {
2020 FlowElementsType ,
2121 FlowFunctionArgumentType ,
22+ FlowLiteralType ,
2223 FlowObjectSignatureType ,
2324 FlowSimpleType ,
2425 FlowTypeDescriptor ,
@@ -54,6 +55,7 @@ const namedTypes = {
5455 TSTupleType : handleTSTupleType ,
5556 TSTypeQuery : handleTSTypeQuery ,
5657 TSTypeOperator : handleTSTypeOperator ,
58+ TSIndexedAccessType : handleTSIndexedAccessType ,
5759} ;
5860
5961function handleTSArrayType (
@@ -347,6 +349,40 @@ function handleTSTypeOperator(path: NodePath): ?FlowTypeDescriptor {
347349 }
348350}
349351
352+ function handleTSIndexedAccessType (
353+ path : NodePath ,
354+ typeParams : ?TypeParameters ,
355+ ) : FlowSimpleType {
356+ // eslint-disable-next-line no-undef
357+ const objectType : $Shape < FlowObjectSignatureType > = getTSTypeWithResolvedTypes(
358+ path.get('objectType'),
359+ typeParams,
360+ );
361+ // eslint-disable-next-line no-undef
362+ const indexType: $Shape< FlowLiteralType > = getTSTypeWithResolvedTypes(
363+ path.get('indexType'),
364+ typeParams,
365+ );
366+
367+ // We only get the signature if the objectType is a type (vs interface)
368+ if (!objectType.signature)
369+ return {
370+ name : `${ objectType . name } [${ indexType . value . toString ( ) } ]` ,
371+ raw : printValue ( path ) ,
372+ } ;
373+ const resolvedType = objectType.signature.properties.find(p => {
374+ // indexType.value = "'foo'"
375+ return p . key === indexType . value . replace ( / [ ' " ] + / g, '' ) ;
376+ } );
377+ if (!resolvedType) {
378+ return { name : 'unknown' } ;
379+ }
380+ return {
381+ name : resolvedType . value . name ,
382+ raw : printValue ( path ) ,
383+ } ;
384+ }
385+
350386let visitedTypes = { } ;
351387
352388function getTSTypeWithResolvedTypes(
0 commit comments