UNPKG

@dfinity/utils

Version:

A collection of utilities and constants for NNS/SNS projects.

24 lines (23 loc) 1.11 kB
export declare class InvalidPercentageError extends Error { } export declare class NullishError extends Error { } export declare const assertNonNullish: <T>(value: T, message?: string) => asserts value is NonNullable<T>; export declare const asNonNullish: <T>(value: T, message?: string) => NonNullable<T>; export declare const assertPercentageNumber: (percentage: number) => void; /** * Utility to enforce exhaustiveness checks in TypeScript. * * This function should only be called in branches of a `switch` or conditional * that should be unreachable if the union type has been fully handled. * * By typing the parameter as `never`, the compiler will emit an error if * a new variant is added to the union but not covered in the logic. * * @param _ - A value that should be of type `never`. If this is not the case, * the TypeScript compiler will flag a type error. * @param message - Optional custom error message to include in the thrown error. * @throws {Error} Always throws when invoked at runtime. * */ export declare const assertNever: (_: never, message?: string) => never;