@knodes/typedoc-pluginutils
Version:
A set of utilities for TypeDoc plugins
49 lines • 2.16 kB
TypeScript
import { Simplify } from 'type-fest';
import { DeclarationOption, DeclarationOptionToOptionType, ParameterTypeToOptionTypeMap } from 'typedoc';
import type { OptionGroup } from './option-group';
import { DeclarationOptionConfig, ParameterValueType } from './utils';
import type { ABasePlugin } from '../base-plugin';
type MapFn<TIn, TOut> = (value: TIn) => TOut;
export type MapperPart<TOpt, TDeclaration extends DeclarationOptionConfig<DeclarationOption>> = ParameterValueType<TDeclaration> extends TOpt ? [
mapper?: MapFn<ParameterValueType<TDeclaration>, TOpt>
] : [
mapper: MapFn<ParameterValueType<TDeclaration>, TOpt>
];
type InferParameterType<T> = keyof {
[key in keyof ParameterTypeToOptionTypeMap as ParameterTypeToOptionTypeMap[key] extends T ? key : never]: true;
};
export type InferDeclarationType<T> = Simplify<DeclarationOption & {
type: InferParameterType<T>;
}>;
export declare class Option<T, TDeclaration extends DeclarationOption = DeclarationOption> {
readonly plugin: ABasePlugin;
readonly group: OptionGroup<any, any> | null;
readonly name: string;
private readonly _mapper;
private readonly _declaration;
get fullName(): string;
/**
* Generate a type-helper factory to constraint the option to be of the given {@link T2 type}.
*
* TODO: change signature once https://github.com/microsoft/TypeScript/pull/26349 is merged.
*
* @param plugin - The plugin declaring the option.
* @returns a function to call with the option declaration (& optional mapper).
*/
static factory<T2>(plugin: ABasePlugin): <TDec extends DeclarationOption>(declaration: TDec, ...mapper: MapperPart<T2, TDec>) => Option<T2, TDec>;
constructor(plugin: ABasePlugin, group: OptionGroup<any, any> | null, declaration: TDeclaration, ...[mapper]: MapperPart<T, TDeclaration>);
/**
* Get the mapped value.
*
* @returns the value.
*/
getValue(): T;
/**
* Set the raw value.
*
* @param value - The value to set.
*/
setValue(value: DeclarationOptionToOptionType<TDeclaration>): void;
}
export {};
//# sourceMappingURL=option.d.ts.map