@codama/renderers-js
Version:
JavaScript renderer compatible with the Solana Kit library
42 lines • 1.66 kB
TypeScript
import { Fragment, RenderScope } from '../utils';
/**
* Renders an enum declaration whose variants are numbered sequentially from zero.
*
* @param scope - The exported name, the variant names and the render scope.
* @returns A {@link Fragment} declaring the enum.
*
* @see {@link getEnumDeclarationFromBodyFragment}
*/
export declare function getEnumDeclarationFragment(scope: Pick<RenderScope, 'erasableSyntax'> & {
name: string;
variantNames: string[];
}): Fragment;
/**
* Renders an enum declaration from an already-rendered object body.
*
* When `erasableSyntax` is enabled, the `enum` keyword is replaced with a `const` object
* and a union type of the same name so the declaration can be erased by a type-stripping
* compiler. The object exposes both its forward and reverse mappings at runtime and in
* TypeScript. The type alias selects only the values of the forward mapping, matching the
* value union of a native enum.
*
* @param scope - The exported name, the object body, an optional docblock and the render scope.
* @returns A {@link Fragment} declaring the enum.
*
* @example
* ```ts
* getEnumDeclarationFromBodyFragment({
* body: fragment`{ 0: 'A', 1: 'B', A: 0, B: 1 }`,
* erasableSyntax: true,
* name: 'Key',
* });
* // export const Key = { 0: 'A', 1: 'B', A: 0, B: 1 } as const;
* // export type Key = (typeof Key)[Exclude<keyof typeof Key, number>];
* ```
*/
export declare function getEnumDeclarationFromBodyFragment(scope: Pick<RenderScope, 'erasableSyntax'> & {
body: Fragment;
docblock?: Fragment;
name: string;
}): Fragment;
//# sourceMappingURL=enumDeclaration.d.ts.map