UNPKG

ts-simple-ast

Version:

TypeScript compiler wrapper for AST navigation and code generation.

58 lines (57 loc) 2.68 kB
import * as ts from "typescript"; import { Constructor } from "./../../Constructor"; import { TypeParameterDeclarationStructure } from "./../../structures"; import { Node } from "./../common"; import { TypeParameterDeclaration } from "./../type/TypeParameterDeclaration"; export declare type TypeParameteredNodeExtensionType = Node<ts.Node & { typeParameters?: ts.NodeArray<ts.TypeParameterDeclaration>; }>; export interface TypeParameteredNode { /** * Gets a type parameter or undefined if it doesn't exist. * @param name - Name of the parameter. */ getTypeParameter(name: string): TypeParameterDeclaration | undefined; /** * Gets a type parameter or undefined if it doesn't exist. * @param findFunction - Function to use to find the type parameter. */ getTypeParameter(findFunction: (declaration: TypeParameterDeclaration) => boolean): TypeParameterDeclaration | undefined; /** * Gets a type parameter or throws if it doesn't exist. * @param name - Name of the parameter. */ getTypeParameterOrThrow(name: string): TypeParameterDeclaration; /** * Gets a type parameter or throws if it doesn't exist. * @param findFunction - Function to use to find the type parameter. */ getTypeParameterOrThrow(findFunction: (declaration: TypeParameterDeclaration) => boolean): TypeParameterDeclaration; /** * Gets the type parameters. */ getTypeParameters(): TypeParameterDeclaration[]; /** * Adds a type parameter. * @param structure - Structure of the type parameter. */ addTypeParameter(structure: TypeParameterDeclarationStructure): TypeParameterDeclaration; /** * Adds type parameters. * @param structures - Structures of the type parameters. */ addTypeParameters(structures: TypeParameterDeclarationStructure[]): TypeParameterDeclaration[]; /** * Inserts a type parameter. * @param index - Index to insert at. Specify a negative index to insert from the reverse. * @param structure - Structure of the type parameter. */ insertTypeParameter(index: number, structure: TypeParameterDeclarationStructure): TypeParameterDeclaration; /** * Inserts type parameters. * @param index - Index to insert at. Specify a negative index to insert from the reverse. * @param structures - Structures of the type parameters. */ insertTypeParameters(index: number, structures: TypeParameterDeclarationStructure[]): TypeParameterDeclaration[]; } export declare function TypeParameteredNode<T extends Constructor<TypeParameteredNodeExtensionType>>(Base: T): Constructor<TypeParameteredNode> & T;