typing-assets
Version:
Additional typing assets and helpers for better TypeScript experience
48 lines • 2.54 kB
TypeScript
/**
* @description Checks types of borrowed variables list
* @param args List of values
* @returns `boolean` - `true` if types are same, `false` if not
*/
export declare const isSameType: (...args: unknown[]) => boolean;
/**
* @description Fucntion generator for custom conditional *type guarding*
* @param callback Condition callback function
* @returns `Arrow function`, which returns `checkingVariable` is `T` *(boolean)*
*/
export declare function generateConditionalGuard<T>(callback: (entity: T) => boolean): (checkingVariable: unknown) => checkingVariable is T;
/**
*
* @description Function generator for *type guarding*
* @param prop Property to check *(must be string or symbol)*
* @param propPrimitive This property `type` alias primitive in string
* @returns `Arrow function`, which returns `checkingVariable` is `T` *(boolean)*
*/
export declare function generateGuard<T>(prop: keyof T, propPrimitive: string | symbol): (checkingVariable: unknown) => checkingVariable is T;
export type Asserter<T> = (checkingVariable: unknown) => asserts checkingVariable is T;
/**
* @param errorMessage Error message `string`
* @param isValid Callback function, that have to return true ro
*
* @returns Type asserter which asserts `checkingVariable` is `T` *(boolean)*
*/
export declare function generateAsserter<T>(errorMessage: string, isValid: (source: unknown, ...args: unknown[]) => boolean): (checkingVariable: unknown) => asserts checkingVariable is T;
export interface Predicates<T> {
guard: ReturnType<typeof generateGuard<T>>;
assert: ReturnType<typeof generateAsserter<T>>;
}
/**
* @description Generates predicates by provided validation callback
* @param errorMessage Error message `string` for *asserter*
* @param validation Validation `callback`, like in *conditional type guard*
* @returns Object with both asserter and type guard
*/
export declare function generatePredicates<T>(errorMessage: string, validation: (source: unknown, ...args: unknown[]) => boolean): Predicates<T>;
/**
* @description Generates predicates by provided property and its primitive
* @param errorMessage Error message `string` for *asserter*
* @param prop Property to check *(must be string or symbol)*
* @param propPrimitive This property `type` alias primitive in string
* @returns Object with both asserter and type guard
*/
export declare function generatePredicates<T>(errorMessage: string, prop: keyof T, propPrimitive: string | symbol): Predicates<T>;
//# sourceMappingURL=predicatesAndTyping.d.ts.map