UNPKG

ts-json-schema-generator

Version:

Generate JSON schema from your Typescript sources

37 lines (36 loc) 1.9 kB
import ts from "typescript"; import type { NodeParser } from "../NodeParser.js"; import { Context } from "../NodeParser.js"; import type { SubNodeParser } from "../SubNodeParser.js"; import type { BaseType } from "../Type/BaseType.js"; declare class CheckType { parameterName: string; type: BaseType; constructor(parameterName: string, type: BaseType); } export declare class ConditionalTypeNodeParser implements SubNodeParser { protected typeChecker: ts.TypeChecker; protected childNodeParser: NodeParser; constructor(typeChecker: ts.TypeChecker, childNodeParser: NodeParser); supportsNode(node: ts.ConditionalTypeNode): boolean; createType(node: ts.ConditionalTypeNode, context: Context): BaseType; /** * Returns the type parameter name of the given type node if any. * * @param node - The type node for which to return the type parameter name. * @return The type parameter name or null if specified type node is not a type parameter. */ protected getTypeParameterName(node: ts.TypeNode): string | null; /** * Creates a sub context for evaluating the sub types of the conditional type. A sub context is needed in case * the check-type is a type parameter which is then narrowed down by the extends-type. * * @param node - The reference node for the new context. * @param checkType - An object containing the type parameter name of the check-type, and the narrowed * down check type to use for the type parameter in sub parsers. * @param inferMap - A map that links parameter names to their inferred types. * @return The created sub context. */ protected createSubContext(node: ts.ConditionalTypeNode, parentContext: Context, checkType?: CheckType, inferMap?: Map<string, BaseType>): Context; } export {};