From 90ead59d34bf5218cf4e1e5317a4ffeb497da8e1 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Thu, 2 Aug 2018 21:09:18 +0200 Subject: Add support for rendering nested IndexSignatures --- packages/react-docs/src/components/interface.tsx | 8 ++--- packages/react-docs/src/components/signature.tsx | 1 - packages/react-docs/src/components/type.tsx | 45 +++++++++++++++++------- 3 files changed, 36 insertions(+), 18 deletions(-) (limited to 'packages/react-docs/src/components') diff --git a/packages/react-docs/src/components/interface.tsx b/packages/react-docs/src/components/interface.tsx index a881c7fec..915b4bbc6 100644 --- a/packages/react-docs/src/components/interface.tsx +++ b/packages/react-docs/src/components/interface.tsx @@ -2,7 +2,7 @@ import * as _ from 'lodash'; import * as React from 'react'; import { DocsInfo } from '../docs_info'; -import { CustomType, TypeDocTypes } from '../types'; +import { CustomType } from '../types'; import { Signature } from './signature'; import { Type } from './type'; @@ -19,9 +19,7 @@ export const Interface = (props: InterfaceProps) => { return ( {property.name}:{' '} - {property.type && property.type.typeDocType !== TypeDocTypes.Reflection ? ( - - ) : ( + {property.type && !_.isUndefined(property.type.method) ? ( { shouldUseArrowSyntax={true} docsInfo={props.docsInfo} /> + ) : ( + )}, ); diff --git a/packages/react-docs/src/components/signature.tsx b/packages/react-docs/src/components/signature.tsx index 5f28050d2..d9567c9f6 100644 --- a/packages/react-docs/src/components/signature.tsx +++ b/packages/react-docs/src/components/signature.tsx @@ -3,7 +3,6 @@ import * as React from 'react'; import { DocsInfo } from '../docs_info'; import { Parameter, Type as TypeDef, TypeDefinitionByName, TypeParameter } from '../types'; -import { constants } from '../utils/constants'; import { Type } from './type'; diff --git a/packages/react-docs/src/components/type.tsx b/packages/react-docs/src/components/type.tsx index 3504be303..ea66c7b1e 100644 --- a/packages/react-docs/src/components/type.tsx +++ b/packages/react-docs/src/components/type.tsx @@ -93,19 +93,38 @@ export function Type(props: TypeProps): any { break; case TypeDocTypes.Reflection: - typeName = ( - - ); + if (!_.isUndefined(type.method)) { + typeName = ( + + ); + } else if (!_.isUndefined(type.indexSignature)) { + const is = type.indexSignature; + const param = ( + + {is.keyName}:{' '} + + + ); + typeName = ( + + {'{'}[{param}]: {is.valueName} + {'}'} + + ); + } else { + throw new Error(`Unrecognized Reflection type that isn't a Method nor an Index Signature`); + } + break; case TypeDocTypes.TypeParameter: -- cgit v1.2.3