@@ -8,6 +8,7 @@ import getTypeParameters from '../utils/getTypeParameters.js';
88import type {
99 ElementsType ,
1010 FunctionSignatureType ,
11+ LiteralType ,
1112 ObjectSignatureType ,
1213 SimpleType ,
1314 TypeDescriptor ,
@@ -20,6 +21,7 @@ import type {
2021 FunctionTypeAnnotation ,
2122 GenericTypeAnnotation ,
2223 Identifier ,
24+ IndexedAccessType ,
2325 InterfaceDeclaration ,
2426 IntersectionTypeAnnotation ,
2527 Node ,
@@ -69,6 +71,7 @@ const namedTypes: Record<
6971 IntersectionTypeAnnotation : handleIntersectionTypeAnnotation ,
7072 TupleTypeAnnotation : handleTupleTypeAnnotation ,
7173 TypeofTypeAnnotation : handleTypeofTypeAnnotation ,
74+ IndexedAccessType : handleIndexedAccessType ,
7275} ;
7376
7477function getFlowTypeWithRequirements (
@@ -413,6 +416,44 @@ function handleTypeofTypeAnnotation(
413416 return getFlowTypeWithResolvedTypes ( path . get ( 'argument' ) , typeParams ) ;
414417}
415418
419+ function handleIndexedAccessType (
420+ path : NodePath < IndexedAccessType > ,
421+ typeParams : TypeParameters | null ,
422+ ) : SimpleType {
423+ const objectType = getFlowTypeWithResolvedTypes (
424+ path . get ( 'objectType' ) ,
425+ typeParams ,
426+ ) as ObjectSignatureType < FunctionSignatureType > ;
427+ const indexType = getFlowTypeWithResolvedTypes (
428+ path . get ( 'indexType' ) ,
429+ typeParams ,
430+ ) as LiteralType ;
431+
432+ // We only get the signature if the objectType is a type (vs interface)
433+ if ( ! objectType . signature ) {
434+ return {
435+ name : `${ objectType . name } [${
436+ indexType . value ? indexType . value . toString ( ) : indexType . name
437+ } ]`,
438+ raw : printValue ( path ) ,
439+ } ;
440+ }
441+
442+ const resolvedType = objectType . signature . properties . find ( ( p ) => {
443+ // indexType.value = "'foo'"
444+ return indexType . value && p . key === indexType . value . replace ( / [ ' " ] + / g, '' ) ;
445+ } ) ;
446+
447+ if ( ! resolvedType ) {
448+ return { name : 'unknown' } ;
449+ }
450+
451+ return {
452+ name : resolvedType . value . name ,
453+ raw : printValue ( path ) ,
454+ } ;
455+ }
456+
416457let visitedTypes : Record < string , TypeDescriptor | boolean > = { } ;
417458
418459function getFlowTypeWithResolvedTypes (
0 commit comments