@eagleoutice/flowr
Version:
Static Dataflow Analyzer and Program Slicer for the R Programming Language
67 lines (66 loc) • 2.4 kB
TypeScript
/** use this to ensure that all cases are covered in case of a selection */
/**
* Verifies, that the given code path is never reached.
* @example
* ```ts
* type Shape = Circle | Square;
* function area(s: Shape): number {
* switch(s.type) {
* case 'circle': return Math.PI * s.radius ** 2;
* case 'square': return s.sideLength ** 2;
* default: return assertUnreachable(s); // ensures that all cases are covered
* }
* }
* ```
*/
export declare function assertUnreachable(x: never): never;
/**
* Verifies that the given value is not undefined.
* This especially helps with a `.filter`
* @example
* ```ts
* const values: (number | undefined)[] = [1, 2, undefined, 4];
* const definedValues: number[] = values.filter(isNotUndefined);
* // definedValues is now of type number[]
* ```
* @see {@link isUndefined}
* @see {@link isNotNull}
*/
export declare function isNotUndefined<T>(this: void, x: T | undefined): x is T;
/**
* Verifies that the given value is undefined.
* This especially helps with a `.filter`
* @example
* ```ts
* const values: (number | undefined)[] = [1, 2, undefined, 4];
* const undefinedValues: undefined[] = values.filter(isUndefined);
* // undefinedValues is now of type undefined[]
* ```
* @see {@link isNotUndefined}
* @see {@link isNotNull}
*/
export declare function isUndefined<T>(this: void, x: T | undefined): x is undefined;
/**
* Verifies that the given value is not null.
* This especially helps with a `.filter`
* @example
* ```ts
* const values: (number | null)[] = [1, 2, null, 4];
* const nonNullValues: number[] = values.filter(isNotNull);
* // nonNullValues is now of type number[]
* ```
* @see {@link isUndefined}
* @see {@link isNotUndefined}
*/
export declare function isNotNull<T>(this: void, x: T | null): x is T;
/**
* Generates a GitHub issue URL for reporting guard errors
*/
export declare function getGuardIssueUrl(message: string): string;
export type GuardMessage = string | (() => string);
/**
* @param assertion - will be asserted
* @param message - if a string, we will use it as the error message, if it is a function, we will call it to produce the error message (can be used to avoid costly message generations)
* @throws GuardError - if the assertion fails
*/
export declare function guard(assertion: unknown | undefined, message?: GuardMessage): asserts assertion;