js-contracts
Version:
C# inspired Code Contracts
24 lines (23 loc) • 1.48 kB
TypeScript
import 'reflect-metadata';
import { ContractCondition, ContractPredicate, ContractSettings } from './types';
export default abstract class Contract {
static setSettings(settings: ContractSettings): void;
static OldValue<T>(value: T): T;
static OldValueByPath<T>(path: string): T;
static ContractResult(): {};
/**
* Not a Decorator. Specifies a condition to test. Executes at the place of call.
* @param condition - The conditional expression to test
* @param message - The message to post if the assumption fails.
*/
static Assert<T extends Error>(condition: ContractCondition, message?: string): (...args: any[]) => void;
static Exists<T, E extends Error>(collection: T[], predicate: ContractPredicate<T>, message?: string): void;
static ForAll<T, E extends Error>(collection: T[], predicate: ContractPredicate<T>, message?: string): void;
static Requires<T extends Error>(condition: ContractCondition, message?: string): (target: Object, key: string | symbol, descriptor: PropertyDescriptor) => PropertyDescriptor;
/**
* Specifies a postcondition contract for the enclosing method or property.
* @param condition - The conditional expression to test
* @param message - The message to post if the assumption fails.
*/
static Ensures<T extends Error>(condition: ContractCondition, message?: string): (target: Object, key: string | symbol, descriptor: PropertyDescriptor) => PropertyDescriptor;
}