@polyipseity/obsidian-plugin-library
Version:
Library for Obsidian plugins.
24 lines • 1.6 kB
TypeScript
import type { AsyncOrSync, Builtin, UnionToIntersection } from "ts-essentials";
import type { DistributeValues } from "./types.js";
import type { PluginContext } from "./plugin.js";
export interface PrivateKeys {
}
export type PrivateKeys$ = keyof PrivateKeys;
export type Private<T, P extends keyof PrivateKeys> = Readonly<Record<P, T>>;
export type HasPrivate<P extends keyof PrivateKeys = PrivateKeys$> = {
readonly [K in P]: Private<unknown, K>;
}[P];
type RevealPrivate0<T> = Omit<T, PrivateKeys$> & UnionToIntersection<DistributeValues<T, PrivateKeys$>>;
export type RevealPrivate<T> = T extends Exclude<Builtin, Error> ? T : RevealPrivate2<T>;
type RevealPrivate2<T> = T extends readonly (infer U)[] ? T extends U[] ? RevealPrivate<U>[] : readonly RevealPrivate<U>[] : RevealPrivate3<T>;
type RevealPrivate3<T> = T extends object ? {
[K in keyof RevealPrivate0<T>]: RevealPrivate<RevealPrivate0<T>[K]>;
} : T;
export declare function revealPrivate<const As extends readonly HasPrivate[], R>(context: PluginContext, args: As, func: (...args: {
readonly [A in keyof As]: RevealPrivate<As[A]>;
}) => R extends PromiseLike<unknown> ? never : R, fallback: (error: unknown) => R extends PromiseLike<unknown> ? never : R): R extends PromiseLike<unknown> ? never : R;
export declare function revealPrivateAsync<const As extends readonly HasPrivate[], R>(context: PluginContext, args: As, func: (...args: {
readonly [A in keyof As]: RevealPrivate<As[A]>;
}) => PromiseLike<R>, fallback: (error: unknown) => AsyncOrSync<R>): Promise<R>;
export {};
//# sourceMappingURL=private.d.ts.map