Add support for rending the Tuple type
This commit is contained in:
@@ -167,6 +167,28 @@ export const Type: React.SFC<TypeProps> = (props: TypeProps): any => {
|
|||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case TypeDocTypes.Tuple:
|
||||||
|
const tupleTypes = _.map(type.tupleElements, t => {
|
||||||
|
return (
|
||||||
|
<Type
|
||||||
|
key={`type-tuple-${t.name}-${t.typeDocType}`}
|
||||||
|
type={t}
|
||||||
|
sectionName={props.sectionName}
|
||||||
|
typeDefinitionByName={props.typeDefinitionByName}
|
||||||
|
docsInfo={props.docsInfo}
|
||||||
|
isInPopover={props.isInPopover}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
typeName = (
|
||||||
|
<div>
|
||||||
|
[{_.reduce(tupleTypes, (prev: React.ReactNode, curr: React.ReactNode) => {
|
||||||
|
return [prev, ', ', curr];
|
||||||
|
})}]
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw errorUtils.spawnSwitchErr('type.typeDocType', type.typeDocType);
|
throw errorUtils.spawnSwitchErr('type.typeDocType', type.typeDocType);
|
||||||
}
|
}
|
||||||
|
@@ -31,6 +31,12 @@ export interface TypeDocType {
|
|||||||
declaration: TypeDocNode;
|
declaration: TypeDocNode;
|
||||||
elementType?: TypeDocType;
|
elementType?: TypeDocType;
|
||||||
indexSignature?: TypeDocNode;
|
indexSignature?: TypeDocNode;
|
||||||
|
elements?: TupleElement[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface TupleElement {
|
||||||
|
type: string;
|
||||||
|
name: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface TypeDocFlags {
|
export interface TypeDocFlags {
|
||||||
@@ -78,6 +84,7 @@ export enum TypeDocTypes {
|
|||||||
Union = 'union',
|
Union = 'union',
|
||||||
TypeParameter = 'typeParameter',
|
TypeParameter = 'typeParameter',
|
||||||
Intersection = 'intersection',
|
Intersection = 'intersection',
|
||||||
|
Tuple = 'tuple',
|
||||||
Unknown = 'unknown',
|
Unknown = 'unknown',
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -157,6 +164,7 @@ export interface Type {
|
|||||||
method?: TypescriptMethod;
|
method?: TypescriptMethod;
|
||||||
indexSignature?: IndexSignature;
|
indexSignature?: IndexSignature;
|
||||||
externalLink?: string;
|
externalLink?: string;
|
||||||
|
tupleElements?: Type[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ElementType {
|
export interface ElementType {
|
||||||
|
@@ -457,6 +457,7 @@ export class TypeDocUtils {
|
|||||||
|
|
||||||
let indexSignatureIfExists;
|
let indexSignatureIfExists;
|
||||||
let methodIfExists;
|
let methodIfExists;
|
||||||
|
let tupleElementsIfExists;
|
||||||
const doesIndexSignatureExist =
|
const doesIndexSignatureExist =
|
||||||
!_.isUndefined(entity.declaration) && !_.isUndefined(entity.declaration.indexSignature);
|
!_.isUndefined(entity.declaration) && !_.isUndefined(entity.declaration.indexSignature);
|
||||||
if (doesIndexSignatureExist) {
|
if (doesIndexSignatureExist) {
|
||||||
@@ -465,6 +466,10 @@ export class TypeDocUtils {
|
|||||||
} else if (!_.isUndefined(entity.declaration)) {
|
} else if (!_.isUndefined(entity.declaration)) {
|
||||||
const isConstructor = false;
|
const isConstructor = false;
|
||||||
methodIfExists = this._convertMethod(entity.declaration, isConstructor, sectionName);
|
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)
|
const elementTypeIfExists = !_.isUndefined(entity.elementType)
|
||||||
@@ -484,6 +489,7 @@ export class TypeDocUtils {
|
|||||||
types,
|
types,
|
||||||
method: methodIfExists,
|
method: methodIfExists,
|
||||||
indexSignature: indexSignatureIfExists,
|
indexSignature: indexSignatureIfExists,
|
||||||
|
tupleElements: tupleElementsIfExists,
|
||||||
};
|
};
|
||||||
const externalLinkIfExists = this._externalTypeToLink[entity.name];
|
const externalLinkIfExists = this._externalTypeToLink[entity.name];
|
||||||
if (!_.isUndefined(externalLinkIfExists)) {
|
if (!_.isUndefined(externalLinkIfExists)) {
|
||||||
|
Reference in New Issue
Block a user