UNPKG

8.13 kBTypeScriptView Raw
1import { Comment } from "../comments/comment";
2import type { ProjectReflection } from "./project";
3import type { NeverIfInternal } from "../../utils";
4import { ReflectionKind } from "./kind";
5import type { Serializer, Deserializer, JSONOutput } from "../../serialization";
6import type { ReflectionVariant } from "./variant";
7import type { DeclarationReflection } from "./declaration";
8import type { DocumentReflection } from "./document";
9import type { Internationalization, TranslatedString } from "../../internationalization";
10/**
11 * Reset the reflection id.
12 *
13 * Used by the test cases to ensure the reflection ids won't change between runs.
14 */
15export declare function resetReflectionID(): void;
16export declare enum ReflectionFlag {
17 None = 0,
18 Private = 1,
19 Protected = 2,
20 Public = 4,
21 Static = 8,
22 External = 16,
23 Optional = 32,
24 Rest = 64,
25 Abstract = 128,
26 Const = 256,
27 Readonly = 512,
28 Inherited = 1024
29}
30/**
31 * This must extend Array in order to work with Handlebar's each helper.
32 */
33export declare class ReflectionFlags {
34 private flags;
35 hasFlag(flag: ReflectionFlag): boolean;
36 /**
37 * Is this a private member?
38 */
39 get isPrivate(): boolean;
40 /**
41 * Is this a protected member?
42 */
43 get isProtected(): boolean;
44 /**
45 * Is this a public member?
46 */
47 get isPublic(): boolean;
48 /**
49 * Is this a static member?
50 */
51 get isStatic(): boolean;
52 /**
53 * Is this a declaration from an external document?
54 */
55 get isExternal(): boolean;
56 /**
57 * Whether this reflection is an optional component or not.
58 *
59 * Applies to function parameters and object members.
60 */
61 get isOptional(): boolean;
62 /**
63 * Whether it's a rest parameter, like `foo(...params);`.
64 */
65 get isRest(): boolean;
66 get isAbstract(): boolean;
67 get isConst(): boolean;
68 get isReadonly(): boolean;
69 get isInherited(): boolean;
70 setFlag(flag: ReflectionFlag, set: boolean): void;
71 getFlagStrings(i18n: Internationalization): TranslatedString[];
72 private setSingleFlag;
73 private static serializedFlags;
74 toObject(): JSONOutput.ReflectionFlags;
75 fromObject(obj: JSONOutput.ReflectionFlags): void;
76}
77export declare enum TraverseProperty {
78 Children = 0,
79 Documents = 1,
80 Parameters = 2,
81 TypeLiteral = 3,
82 TypeParameter = 4,
83 Signatures = 5,
84 IndexSignature = 6,
85 GetSignature = 7,
86 SetSignature = 8
87}
88export interface TraverseCallback {
89 /**
90 * May return false to bail out of any further iteration. To preserve backwards compatibility, if
91 * a function returns undefined, iteration must continue.
92 */
93 (reflection: Reflection, property: TraverseProperty): boolean | NeverIfInternal<void>;
94}
95export type ReflectionVisitor = {
96 [K in keyof ReflectionVariant]?: (refl: ReflectionVariant[K]) => void;
97};
98/**
99 * Base class for all reflection classes.
100 *
101 * While generating a documentation, TypeDoc generates an instance of {@link ProjectReflection}
102 * as the root for all reflections within the project. All other reflections are represented
103 * by the {@link DeclarationReflection} class.
104 *
105 * This base class exposes the basic properties one may use to traverse the reflection tree.
106 * You can use the {@link ContainerReflection.children} and {@link parent} properties to walk the tree. The {@link ContainerReflection.groups} property
107 * contains a list of all children grouped and sorted for rendering.
108 * @category Reflections
109 */
110export declare abstract class Reflection {
111 /**
112 * Discriminator representing the type of reflection represented by this object.
113 */
114 abstract readonly variant: keyof ReflectionVariant;
115 /**
116 * Unique id of this reflection.
117 */
118 id: number;
119 /**
120 * The symbol name of this reflection.
121 */
122 name: string;
123 /**
124 * The kind of this reflection.
125 */
126 kind: ReflectionKind;
127 flags: ReflectionFlags;
128 /**
129 * The reflection this reflection is a child of.
130 */
131 parent?: Reflection;
132 project: ProjectReflection;
133 /**
134 * The parsed documentation comment attached to this reflection.
135 */
136 comment?: Comment;
137 /**
138 * The url of this reflection in the generated documentation.
139 * TODO: Reflections shouldn't know urls exist. Move this to a serializer.
140 */
141 url?: string;
142 /**
143 * The name of the anchor of this child.
144 * TODO: Reflections shouldn't know anchors exist. Move this to a serializer.
145 */
146 anchor?: string;
147 /**
148 * Is the url pointing to an individual document?
149 *
150 * When FALSE, the url points to an anchor tag on a page of a different reflection.
151 * TODO: Reflections shouldn't know how they are rendered. Move this to the correct serializer.
152 */
153 hasOwnDocument?: boolean;
154 /**
155 * Url safe alias for this reflection.
156 */
157 private _alias?;
158 private _aliases?;
159 constructor(name: string, kind: ReflectionKind, parent?: Reflection);
160 /**
161 * Test whether this reflection is of the given kind.
162 */
163 kindOf(kind: ReflectionKind | ReflectionKind[]): boolean;
164 /**
165 * Return the full name of this reflection. Intended for use in debugging. For log messages
166 * intended to be displayed to the user for them to fix, prefer {@link getFriendlyFullName} instead.
167 *
168 * The full name contains the name of this reflection and the names of all parent reflections.
169 *
170 * @param separator Separator used to join the names of the reflections.
171 * @returns The full name of this reflection.
172 */
173 getFullName(separator?: string): string;
174 /**
175 * Return the full name of this reflection, with signature names dropped if possible without
176 * introducing ambiguity in the name.
177 */
178 getFriendlyFullName(): string;
179 /**
180 * Set a flag on this reflection.
181 */
182 setFlag(flag: ReflectionFlag, value?: boolean): void;
183 /**
184 * Return an url safe alias for this reflection.
185 */
186 getAlias(): string;
187 getUniqueAliasInPage(heading: string): string;
188 /**
189 * Has this reflection a visible comment?
190 *
191 * @returns TRUE when this reflection has a visible comment.
192 */
193 hasComment(): boolean;
194 hasGetterOrSetter(): boolean;
195 /**
196 * Return a child by its name.
197 *
198 * @param arg The name hierarchy of the child to look for.
199 * @returns The found child or undefined.
200 */
201 getChildByName(arg: string | string[]): Reflection | undefined;
202 /**
203 * Return whether this reflection is the root / project reflection.
204 */
205 isProject(): this is ProjectReflection;
206 isDeclaration(): this is DeclarationReflection;
207 isDocument(): this is DocumentReflection;
208 /**
209 * Check if this reflection or any of its parents have been marked with the `@deprecated` tag.
210 */
211 isDeprecated(): boolean;
212 /**
213 * Traverse most potential child reflections of this reflection.
214 *
215 * Note: This may not necessarily traverse child reflections contained within the `type` property
216 * of the reflection, and should not be relied on for this. Support for checking object types will likely be removed in v0.27.
217 *
218 * The given callback will be invoked for all children, signatures and type parameters
219 * attached to this reflection.
220 *
221 * @param callback The callback function that should be applied for each child reflection.
222 */
223 abstract traverse(callback: TraverseCallback): void;
224 visit(visitor: ReflectionVisitor): void;
225 /**
226 * Return a string representation of this reflection.
227 */
228 toString(): string;
229 /**
230 * Return a string representation of this reflection and all of its children.
231 *
232 * Note: This is intended as a debug tool only, output may change between patch versions.
233 *
234 * @param indent Used internally to indent child reflections.
235 */
236 toStringHierarchy(indent?: string): string;
237 toObject(serializer: Serializer): JSONOutput.Reflection;
238 fromObject(de: Deserializer, obj: JSONOutput.Reflection): void;
239}