UNPKG

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