UNPKG

17.1 kBTypeScriptView Raw
1import type { BundledTheme as ShikiTheme } from "shiki" with { "resolution-mode": "import" };
2import type { LogLevel } from "../loggers";
3import type { SortStrategy } from "../sort";
4import type { EntryPointStrategy } from "../entry-point";
5import type { ReflectionKind } from "../../models/reflections/kind";
6import type { NeverIfInternal } from "..";
7import type { TranslationProxy } from "../../internationalization/internationalization";
8/** @enum */
9export declare const EmitStrategy: {
10 readonly both: "both";
11 readonly docs: "docs";
12 readonly none: "none";
13};
14/** @hidden */
15export type EmitStrategy = (typeof EmitStrategy)[keyof typeof EmitStrategy];
16/**
17 * Determines how TypeDoc searches for comments.
18 * @enum
19 */
20export declare const CommentStyle: {
21 readonly JSDoc: "jsdoc";
22 readonly Block: "block";
23 readonly Line: "line";
24 readonly All: "all";
25};
26export type CommentStyle = (typeof CommentStyle)[keyof typeof CommentStyle];
27/**
28 * An interface describing all TypeDoc specific options. Generated from a
29 * map which contains more information about each option for better types when
30 * defining said options.
31 * @interface
32 */
33export type TypeDocOptions = {
34 [K in keyof TypeDocOptionMap]: unknown extends TypeDocOptionMap[K] ? unknown : TypeDocOptionMap[K] extends ManuallyValidatedOption<infer ManuallyValidated> ? ManuallyValidated : TypeDocOptionMap[K] extends string | string[] | number | boolean ? TypeDocOptionMap[K] : TypeDocOptionMap[K] extends Record<string, boolean> ? Partial<TypeDocOptionMap[K]> | boolean : keyof TypeDocOptionMap[K] | TypeDocOptionMap[K][keyof TypeDocOptionMap[K]];
35};
36/**
37 * Describes all TypeDoc specific options as returned by {@link Options.getValue}, this is
38 * slightly more restrictive than the {@link TypeDocOptions} since it does not allow both
39 * keys and values for mapped option types, and does not allow partials of flag values.
40 * @interface
41 */
42export type TypeDocOptionValues = {
43 [K in keyof TypeDocOptionMap]: unknown extends TypeDocOptionMap[K] ? unknown : TypeDocOptionMap[K] extends ManuallyValidatedOption<infer ManuallyValidated> ? ManuallyValidated : TypeDocOptionMap[K] extends string | string[] | number | boolean | Record<string, boolean> ? TypeDocOptionMap[K] : TypeDocOptionMap[K][keyof TypeDocOptionMap[K]];
44};
45/**
46 * Describes all TypeDoc options. Used internally to provide better types when fetching options.
47 * External consumers should likely use {@link TypeDocOptions} instead.
48 *
49 * If writing a plugin, you may find it useful to use declaration merging to add your options to this interface
50 * so that you have autocomplete when using `app.options.getValue`.
51 *
52 * ```ts
53 * declare module "typedoc" {
54 * export interface TypeDocOptionMap {
55 * pluginOption: string[];
56 * }
57 * }
58 * ```
59 */
60export interface TypeDocOptionMap {
61 options: string;
62 tsconfig: string;
63 compilerOptions: unknown;
64 plugin: string[];
65 lang: string;
66 locales: ManuallyValidatedOption<Record<string, Record<string, string>>>;
67 packageOptions: ManuallyValidatedOption<TypeDocOptions>;
68 entryPoints: string[];
69 entryPointStrategy: typeof EntryPointStrategy;
70 alwaysCreateEntryPointModule: boolean;
71 projectDocuments: string[];
72 exclude: string[];
73 externalPattern: string[];
74 excludeExternals: boolean;
75 excludeNotDocumented: boolean;
76 excludeNotDocumentedKinds: ReflectionKind.KindString[];
77 excludeInternal: boolean;
78 excludePrivate: boolean;
79 excludeProtected: boolean;
80 excludeReferences: boolean;
81 excludeCategories: string[];
82 maxTypeConversionDepth: number;
83 name: string;
84 includeVersion: boolean;
85 disableSources: boolean;
86 sourceLinkTemplate: string;
87 sourceLinkExternal: boolean;
88 markdownLinkExternal: boolean;
89 disableGit: boolean;
90 gitRevision: string;
91 gitRemote: string;
92 readme: string;
93 out: string;
94 json: string;
95 pretty: boolean;
96 emit: typeof EmitStrategy;
97 theme: string;
98 lightHighlightTheme: ShikiTheme;
99 darkHighlightTheme: ShikiTheme;
100 highlightLanguages: string[];
101 customCss: string;
102 customJs: string;
103 markdownItOptions: ManuallyValidatedOption<Record<string, unknown>>;
104 /**
105 * Will be called when TypeDoc is setting up the markdown parser to use to render markdown.
106 * Can be used to add markdown-it plugins to the parser with code like this:
107 *
108 * ```ts
109 * // typedoc.config.mjs
110 * import iterator from "markdown-it-for-inline";
111 * export default {
112 * /** @param {MarkdownIt} parser *\/
113 * markdownItLoader(parser) {
114 * parser.use(iterator, "foo_replace", "text", function(tokens, idx) {
115 * tokens[idx].content = tokens[idx].content.replace(/foo/g, 'bar');
116 * });
117 * }
118 * }
119 * ```
120 *
121 * Note: Unfortunately, markdown-it doesn't ship its own types, so `parser` isn't
122 * strictly typed here.
123 */
124 markdownItLoader: ManuallyValidatedOption<(parser: any) => void>;
125 basePath: string;
126 cname: string;
127 githubPages: boolean;
128 hostedBaseUrl: string;
129 useHostedBaseUrlForAbsoluteLinks: boolean;
130 cacheBust: boolean;
131 hideGenerator: boolean;
132 customFooterHtml: string;
133 customFooterHtmlDisableWrapper: boolean;
134 hideParameterTypesInTitle: boolean;
135 searchInComments: boolean;
136 searchInDocuments: boolean;
137 cleanOutputDir: boolean;
138 titleLink: string;
139 navigationLinks: ManuallyValidatedOption<Record<string, string>>;
140 sidebarLinks: ManuallyValidatedOption<Record<string, string>>;
141 navigationLeaves: string[];
142 navigation: {
143 includeCategories: boolean;
144 includeGroups: boolean;
145 includeFolders: boolean;
146 compactFolders: boolean;
147 excludeReferences: boolean;
148 };
149 headings: {
150 readme: boolean;
151 document: boolean;
152 };
153 visibilityFilters: ManuallyValidatedOption<{
154 protected?: boolean;
155 private?: boolean;
156 inherited?: boolean;
157 external?: boolean;
158 [tag: `@${string}`]: boolean;
159 }>;
160 searchCategoryBoosts: ManuallyValidatedOption<Record<string, number>>;
161 searchGroupBoosts: ManuallyValidatedOption<Record<string, number>>;
162 commentStyle: typeof CommentStyle;
163 useTsLinkResolution: boolean;
164 preserveLinkText: boolean;
165 jsDocCompatibility: JsDocCompatibility;
166 suppressCommentWarningsInDeclarationFiles: boolean;
167 blockTags: `@${string}`[];
168 inlineTags: `@${string}`[];
169 modifierTags: `@${string}`[];
170 excludeTags: `@${string}`[];
171 externalSymbolLinkMappings: ManuallyValidatedOption<Record<string, Record<string, string>>>;
172 cascadedModifierTags: `@${string}`[];
173 categorizeByGroup: boolean;
174 defaultCategory: string;
175 categoryOrder: string[];
176 groupOrder: string[];
177 sort: SortStrategy[];
178 sortEntryPoints: boolean;
179 kindSortOrder: ReflectionKind.KindString[];
180 treatWarningsAsErrors: boolean;
181 treatValidationWarningsAsErrors: boolean;
182 intentionallyNotExported: string[];
183 validation: ValidationOptions;
184 requiredToBeDocumented: ReflectionKind.KindString[];
185 watch: boolean;
186 preserveWatchOutput: boolean;
187 help: boolean;
188 version: boolean;
189 showConfig: boolean;
190 logLevel: typeof LogLevel;
191 skipErrorChecking: boolean;
192}
193/**
194 * Wrapper type for values in TypeDocOptionMap which are represented with an unknown option type, but
195 * have a validation function that checks that they are the given type.
196 */
197export type ManuallyValidatedOption<T> = {
198 __validated: T;
199};
200export type ValidationOptions = {
201 /**
202 * If set, TypeDoc will produce warnings when a symbol is referenced by the documentation,
203 * but is not included in the documentation.
204 */
205 notExported: boolean;
206 /**
207 * If set, TypeDoc will produce warnings about \{\@link\} tags which will produce broken links.
208 */
209 invalidLink: boolean;
210 /**
211 * If set, TypeDoc will produce warnings about declarations that do not have doc comments
212 */
213 notDocumented: boolean;
214};
215export type JsDocCompatibility = {
216 /**
217 * If set, TypeDoc will treat `@example` blocks as code unless they contain a code block.
218 * On by default, this is how VSCode renders blocks.
219 */
220 exampleTag: boolean;
221 /**
222 * If set, TypeDoc will treat `@default` blocks as code unless they contain a code block.
223 * On by default, this is how VSCode renders blocks.
224 */
225 defaultTag: boolean;
226 /**
227 * If set, TypeDoc will warn if a `@inheritDoc` tag is spelled without TSDoc capitalization
228 * (i.e. `@inheritdoc`). On by default.
229 */
230 inheritDocTag: boolean;
231 /**
232 * If set, TypeDoc will not emit warnings about unescaped `{` and `}` characters encountered
233 * when parsing a comment. On by default.
234 */
235 ignoreUnescapedBraces: boolean;
236};
237/**
238 * Converts a given TypeDoc option key to the type of the declaration expected.
239 */
240export type KeyToDeclaration<K extends keyof TypeDocOptionMap> = TypeDocOptionMap[K] extends boolean ? BooleanDeclarationOption : TypeDocOptionMap[K] extends string ? StringDeclarationOption : TypeDocOptionMap[K] extends number ? NumberDeclarationOption : TypeDocOptionMap[K] extends string[] ? ArrayDeclarationOption : unknown extends TypeDocOptionMap[K] ? MixedDeclarationOption | ObjectDeclarationOption : TypeDocOptionMap[K] extends ManuallyValidatedOption<unknown> ? (MixedDeclarationOption & {
241 validate(value: unknown, i18n: TranslationProxy): void;
242}) | (ObjectDeclarationOption & {
243 validate(value: unknown, i18n: TranslationProxy): void;
244}) : TypeDocOptionMap[K] extends Record<string, boolean> ? FlagsDeclarationOption<TypeDocOptionMap[K]> : TypeDocOptionMap[K] extends Record<string | number, infer U> ? MapDeclarationOption<U> : never;
245export declare enum ParameterHint {
246 File = 0,
247 Directory = 1
248}
249export declare enum ParameterType {
250 String = 0,
251 /**
252 * Resolved according to the config directory.
253 */
254 Path = 1,
255 Number = 2,
256 Boolean = 3,
257 Map = 4,
258 Mixed = 5,
259 Array = 6,
260 /**
261 * Resolved according to the config directory.
262 */
263 PathArray = 7,
264 /**
265 * Resolved according to the config directory if it starts with `.`
266 */
267 ModuleArray = 8,
268 /**
269 * Resolved according to the config directory unless it starts with `**`, after skipping any leading `!` and `#` characters.
270 */
271 GlobArray = 9,
272 /**
273 * An object which partially merges user-set values into the defaults.
274 */
275 Object = 10,
276 /**
277 * An object with true/false flags
278 */
279 Flags = 11
280}
281export interface DeclarationOptionBase {
282 /**
283 * The option name.
284 */
285 name: string;
286 /**
287 * The help text to be displayed to the user when --help is passed.
288 *
289 * This may be a string, which will be presented directly, or a function,
290 * which will be called with an {@link TranslationProxy} so that option help
291 * can be translated into the user specified locale.
292 */
293 help: NeverIfInternal<string> | ((i18n: TranslationProxy) => string);
294 /**
295 * The parameter type, used to convert user configuration values into the expected type.
296 * If not set, the type will be a string.
297 */
298 type?: ParameterType;
299 /**
300 * If set, this option will be omitted from `--help`, and attempting to specify it on the command
301 * line will produce an error.
302 */
303 configFileOnly?: boolean;
304}
305export interface StringDeclarationOption extends DeclarationOptionBase {
306 /**
307 * Specifies the resolution strategy. If `Path` is provided, values will be resolved according to their
308 * location in a file. If `String` or no value is provided, values will not be resolved.
309 */
310 type?: ParameterType.String | ParameterType.Path;
311 /**
312 * If not specified defaults to the empty string for both `String` and `Path`.
313 */
314 defaultValue?: string;
315 /**
316 * An optional hint for the type of input expected, will be displayed in the help output.
317 */
318 hint?: ParameterHint;
319 /**
320 * An optional validation function that validates a potential value of this option.
321 * The function must throw an Error if the validation fails and should do nothing otherwise.
322 */
323 validate?: (value: string, i18n: TranslationProxy) => void;
324}
325export interface NumberDeclarationOption extends DeclarationOptionBase {
326 type: ParameterType.Number;
327 /**
328 * Lowest possible value.
329 */
330 minValue?: number;
331 /**
332 * Highest possible value.
333 */
334 maxValue?: number;
335 /**
336 * If not specified defaults to 0.
337 */
338 defaultValue?: number;
339 /**
340 * An optional validation function that validates a potential value of this option.
341 * The function must throw an Error if the validation fails and should do nothing otherwise.
342 */
343 validate?: (value: number, i18n: TranslationProxy) => void;
344}
345export interface BooleanDeclarationOption extends DeclarationOptionBase {
346 type: ParameterType.Boolean;
347 /**
348 * If not specified defaults to false.
349 */
350 defaultValue?: boolean;
351}
352export interface ArrayDeclarationOption extends DeclarationOptionBase {
353 type: ParameterType.Array | ParameterType.PathArray | ParameterType.ModuleArray | ParameterType.GlobArray;
354 /**
355 * If not specified defaults to an empty array.
356 */
357 defaultValue?: readonly string[];
358 /**
359 * An optional validation function that validates a potential value of this option.
360 * The function must throw an Error if the validation fails and should do nothing otherwise.
361 */
362 validate?: (value: string[], i18n: TranslationProxy) => void;
363}
364export interface MixedDeclarationOption extends DeclarationOptionBase {
365 type: ParameterType.Mixed;
366 /**
367 * If not specified defaults to undefined.
368 */
369 defaultValue?: unknown;
370 /**
371 * An optional validation function that validates a potential value of this option.
372 * The function must throw an Error if the validation fails and should do nothing otherwise.
373 */
374 validate?: (value: unknown, i18n: TranslationProxy) => void;
375}
376export interface ObjectDeclarationOption extends DeclarationOptionBase {
377 type: ParameterType.Object;
378 /**
379 * If not specified defaults to undefined.
380 */
381 defaultValue?: unknown;
382 /**
383 * An optional validation function that validates a potential value of this option.
384 * The function must throw an Error if the validation fails and should do nothing otherwise.
385 */
386 validate?: (value: unknown, i18n: TranslationProxy) => void;
387}
388export interface MapDeclarationOption<T> extends DeclarationOptionBase {
389 type: ParameterType.Map;
390 /**
391 * Maps a given value to the option type. The map type may be a TypeScript enum.
392 * In that case, when generating an error message for a mismatched key, the numeric
393 * keys will not be listed.
394 */
395 map: Map<string, T> | Record<string | number, T>;
396 /**
397 * Unlike the rest of the option types, there is no sensible generic default for mapped option types.
398 * The default value for a mapped type must be specified.
399 */
400 defaultValue: T;
401}
402export interface FlagsDeclarationOption<T extends Record<string, boolean>> extends DeclarationOptionBase {
403 type: ParameterType.Flags;
404 /**
405 * All of the possible flags, with their default values set.
406 */
407 defaults: T;
408}
409export type DeclarationOption = StringDeclarationOption | NumberDeclarationOption | BooleanDeclarationOption | MixedDeclarationOption | ObjectDeclarationOption | MapDeclarationOption<unknown> | ArrayDeclarationOption | FlagsDeclarationOption<Record<string, boolean>>;
410export interface ParameterTypeToOptionTypeMap {
411 [ParameterType.String]: string;
412 [ParameterType.Path]: string;
413 [ParameterType.Number]: number;
414 [ParameterType.Boolean]: boolean;
415 [ParameterType.Mixed]: unknown;
416 [ParameterType.Object]: unknown;
417 [ParameterType.Array]: string[];
418 [ParameterType.PathArray]: string[];
419 [ParameterType.ModuleArray]: string[];
420 [ParameterType.GlobArray]: string[];
421 [ParameterType.Flags]: Record<string, boolean>;
422 [ParameterType.Map]: unknown;
423}
424export type DeclarationOptionToOptionType<T extends DeclarationOption> = T extends MapDeclarationOption<infer U> ? U : T extends FlagsDeclarationOption<infer U> ? U : ParameterTypeToOptionTypeMap[Exclude<T["type"], undefined>];
425/**
426 * The default conversion function used by the Options container. Readers may
427 * re-use this conversion function or implement their own. The arguments reader
428 * implements its own since 'false' should not be converted to true for a boolean option.
429 * @param value The value to convert.
430 * @param option The option for which the value should be converted.
431 * @returns The result of the conversion. Might be the value or an error.
432 */
433export declare function convert(value: unknown, option: DeclarationOption, i18n: TranslationProxy, configPath: string, oldValue?: unknown): unknown;
434export declare function getDefaultValue(option: DeclarationOption): unknown;