@irwinproject/storybook-addon-tsdoc
Version:
Generate mdx documentation from your typescript!
209 lines (208 loc) • 7.87 kB
TypeScript
import { ArrayBindingPattern, ArrayLiteralExpression, ArrowFunction, ClassDeclaration, ClassExpression, EnumMember, ExpressionableNode, ExtendsClauseableNode, FunctionDeclaration, FunctionExpression, FunctionTypeNode, GetAccessorDeclaration, Identifier, InterfaceDeclaration, IntersectionTypeNode, LiteralTypeNode, MethodDeclaration, MethodSignature, NamedTupleMember, NewExpression, Node, ParameterDeclaration, PropertyAccessExpression, PropertyAssignment, PropertyDeclaration, PropertySignature, ReturnTypedNode, TupleTypeNode, Type, TypeAliasDeclaration, TypeOperatorTypeNode, TypeParameterDeclaration, TypeReferenceNode, UnionTypeNode, VariableDeclaration } from "ts-morph";
import { Nodely } from "./types";
/**
* Diving down to the underlying type provides lower level access to the typing however ts-morph provides a wonderul interface via their Node class. Since it completely crawls the Source File it seems more suitable to get the dclaration that is being referenced
* @param t
* @returns
*/
export declare const fromType: (t: Type | undefined) => string;
/**
* Attempts to get a type node from the types declaration.
* @param node
* @returns
*/
export declare const getSignatureFromType: (node: Nodely) => string;
/**
* This mod handler simply attempts to parse the name node. This should ultimately end with an identifier but also allow for potential destructured objects to be traversed without change of logic.
* @param node
* @returns
*/
export declare const fromName: (node: Node) => string;
export declare const getExpression: (node: ExpressionableNode | NewExpression) => string;
/**
* With typenodes not alway being provided this method acts as a point where I can change the logic if getting a typenode fails.
* @param node
* @returns
*/
export declare const fromTypeNode: (node: Node) => string;
/**
* Returns can be explicit or inferred.
*
* Similar to a typenode on how its handled.
* @todo - prior to checking the type check the jsdocs for a returns or return tag
* @todo - traverse the body and collect return expressions manually (this is purely to allow differenciation between class instances and class constructors being returned in the expression.)
* @param node
* @returns
*/
export declare const fromReturn: (node: ReturnTypedNode) => string;
/**
* A convenience method to signature and wrap a statement
* @param nodes
* @param pre
* @param post
* @returns
*/
export declare const genTypes: (nodes: Node[], pre?: string, post?: string) => string;
/**
* Checks if a node is a generator. This is made generic as Arrow functions cant be generators but aside from that can do just about anything else a function can so it does not make sense to have two separate signators.
* @param node
* @returns
*/
export declare const isGenerator: (node: Node) => any;
/**
* Returns a literal representation of {...}
* @returns
*/
export declare const objLiteral: () => string;
/**
* Converts modifier tokens to plain text
* @todo style this maybe.
* @param node
* @returns
*/
export declare const getModifiers: (node: Node) => string;
/**
* document a contraint
* @param node
* @returns
*/
export declare const getConstraint: (node: TypeParameterDeclaration) => string;
export declare const getImplements: (node: ClassDeclaration | ClassExpression) => string;
export declare const getExtend: (node: ClassDeclaration | ClassExpression) => string;
export declare const getExtends: (node: ExtendsClauseableNode) => string;
/**
* Returns the appropriate operator based on syntax kind.
*
* could probably just use getText.
* @param node
* @returns
*/
export declare const getOperator: (node: TypeOperatorTypeNode) => "readonly" | "keyof" | "unique";
/**
* Checks if value has a question token and if so passes it to the signature.
* @param node
* @returns
*/
export declare const opt: (node: Node) => "" | "?";
/**
* Checks if a spread symbol precedes the node and if so passes it to the signature.
* @param node
* @returns
*/
export declare const spread: (node: Node) => "" | "...";
/**
* documents a potential async modifier
* @param node
* @returns
*/
export declare const getAsync: (node: Node) => "" | "async ";
/**
* documents a potential generator modifier.
* @param node
* @returns
*/
export declare const getGenerator: (node: Node) => "" | "*";
/**
* documents type parameters.
* @param node
* @returns
*/
export declare const getTypeParameters: (node: Node) => string;
export declare const getTypeArguments: (node: Node) => string;
/**
* Documents a functions arguments (aka: parameters).
* @param node
* @returns
*/
export declare const getArguments: (node: Node) => string;
/**
* These two declaration types share a common signature. no point in repeating myself.
* Document a proprty type declaration.
* @param node
* @returns
*/
export declare const propertyDecSig: (node: PropertyDeclaration | PropertySignature | PropertyAssignment) => string;
/**
* Document a function type declaration.
* @param node
* @returns
*/
export declare const fnSignature: (node: FunctionDeclaration | FunctionExpression | MethodDeclaration | FunctionTypeNode | MethodSignature | ArrowFunction) => string;
/**
* document a named tuple member.
* @param node
* @returns
*/
export declare const namedTupleMember: (node: NamedTupleMember) => string;
/**
* document a property access expression.
* @param node
* @returns
*/
export declare const propertyAccessExpression: (node: PropertyAccessExpression) => string;
/**
* Get the type alias declaration
* @param node
* @returns
*/
export declare const typeAliasDeclaration: (node: TypeAliasDeclaration) => string;
/**
* Document a union type.
* @param node
* @returns
*/
export declare const unionType: (node: UnionTypeNode) => string;
/**
* Document an intersection type.
* @param node
* @returns
*/
export declare const intersectionType: (node: IntersectionTypeNode) => string;
/**
* document a literal type
* @param node
* @returns
*/
export declare const literalType: (node: LiteralTypeNode) => string;
/**
* document an array literal
* @param node
* @returns
*/
export declare const arrayLiteral: (node: ArrayLiteralExpression | TupleTypeNode | ArrayBindingPattern) => string;
/**
* document a type reference. funny thing the type reference doesnt create a link.
* @param node
* @returns
*/
export declare const typeReference: (node: TypeReferenceNode) => string;
/**
* An identifier is a sort of reference that points to a definition. if theres a definition and the definition doesnt point back to said node then it becomes a link.
* @todo test this with destructured nodes.
* @param node
* @returns
*/
export declare const identifier: (node: Identifier) => string;
/**
* A type parameter
* @param node
* @returns
*/
export declare const typeParameter: (node: TypeParameterDeclaration) => string;
/**
* A parameter is a little different then a normal expression in typescript with a parameter typing should be expected or default to any and the initializer should not be used when a typeNode is not present. Also the typ should not be used for this same reason.
* @param node
*/
export declare const parameter: (node: ParameterDeclaration) => string;
/**
* A class declaration and class express differ at one point and thats the name.
* @param node
* @returns
*/
export declare const classDeclaration: (node: ClassDeclaration | ClassExpression) => string;
export declare const interfaceDeclaration: (node: InterfaceDeclaration) => string;
export declare const getAccessor: (node: GetAccessorDeclaration) => string;
export declare const variableDeclaration: (node: VariableDeclaration) => string;
export declare const newExpression: (node: NewExpression) => string;
export declare const literal: (node: Node) => string;
export declare const enummember: (node: EnumMember) => string;