From 28f077b16f5fc5f08f95bb2ad00724e6ea89dd00 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Thu, 23 Aug 2018 16:55:41 +0100 Subject: Add support for rending the Tuple type --- packages/react-docs/src/components/type.tsx | 22 ++++++++++++++++++++++ packages/react-docs/src/types.ts | 8 ++++++++ packages/react-docs/src/utils/typedoc_utils.ts | 6 ++++++ 3 files changed, 36 insertions(+) (limited to 'packages') diff --git a/packages/react-docs/src/components/type.tsx b/packages/react-docs/src/components/type.tsx index 145c797a3..5f7601ce1 100644 --- a/packages/react-docs/src/components/type.tsx +++ b/packages/react-docs/src/components/type.tsx @@ -167,6 +167,28 @@ export const Type: React.SFC = (props: TypeProps): any => { }); break; + case TypeDocTypes.Tuple: + const tupleTypes = _.map(type.tupleElements, t => { + return ( + + ); + }); + typeName = ( +
+ [{_.reduce(tupleTypes, (prev: React.ReactNode, curr: React.ReactNode) => { + return [prev, ', ', curr]; + })}] +
+ ); + break; + default: throw errorUtils.spawnSwitchErr('type.typeDocType', type.typeDocType); } diff --git a/packages/react-docs/src/types.ts b/packages/react-docs/src/types.ts index 7fd785e32..f9cb5e26a 100644 --- a/packages/react-docs/src/types.ts +++ b/packages/react-docs/src/types.ts @@ -31,6 +31,12 @@ export interface TypeDocType { declaration: TypeDocNode; elementType?: TypeDocType; indexSignature?: TypeDocNode; + elements?: TupleElement[]; +} + +export interface TupleElement { + type: string; + name: string; } export interface TypeDocFlags { @@ -78,6 +84,7 @@ export enum TypeDocTypes { Union = 'union', TypeParameter = 'typeParameter', Intersection = 'intersection', + Tuple = 'tuple', Unknown = 'unknown', } @@ -157,6 +164,7 @@ export interface Type { method?: TypescriptMethod; indexSignature?: IndexSignature; externalLink?: string; + tupleElements?: Type[]; } export interface ElementType { diff --git a/packages/react-docs/src/utils/typedoc_utils.ts b/packages/react-docs/src/utils/typedoc_utils.ts index b867b51b4..67e37e82d 100644 --- a/packages/react-docs/src/utils/typedoc_utils.ts +++ b/packages/react-docs/src/utils/typedoc_utils.ts @@ -457,6 +457,7 @@ export class TypeDocUtils { let indexSignatureIfExists; let methodIfExists; + let tupleElementsIfExists; const doesIndexSignatureExist = !_.isUndefined(entity.declaration) && !_.isUndefined(entity.declaration.indexSignature); if (doesIndexSignatureExist) { @@ -465,6 +466,10 @@ export class TypeDocUtils { } else if (!_.isUndefined(entity.declaration)) { const isConstructor = false; methodIfExists = this._convertMethod(entity.declaration, isConstructor, sectionName); + } else if (entity.type === TypeDocTypes.Tuple) { + tupleElementsIfExists = _.map(entity.elements, el => { + return { name: el.name, typeDocType: el.type as TypeDocTypes }; + }); } const elementTypeIfExists = !_.isUndefined(entity.elementType) @@ -484,6 +489,7 @@ export class TypeDocUtils { types, method: methodIfExists, indexSignature: indexSignatureIfExists, + tupleElements: tupleElementsIfExists, }; const externalLinkIfExists = this._externalTypeToLink[entity.name]; if (!_.isUndefined(externalLinkIfExists)) { -- cgit v1.2.3