UNPKG

@holgerengels/compute-engine

Version:

Symbolic computing and numeric evaluations for JavaScript and Node.js

40 lines (39 loc) 1.76 kB
/* 0.26.0-alpha2 */ import { Type, FunctionSignature, TypeString } from './types'; /** Convert two or more types into a more specific type that is a subtype of * all the input types. The resulting type is usually more constrained and * only encompasses values that belong to both input types. * * Examples: * narrow('integer', 'rational') => 'integer' * narrow('number', 'complex') => 'complex' * narrow('number', 'collection') => 'nothing' * narrow('number', 'value') => 'value' * narrow('number', 'expression') => 'expression' * narrow('number', 'string') => 'nothing' * * */ export declare function narrow(...types: Readonly<Type>[]): Type; /** * Convert two or more types into a broader, more general type that can * accommodate all the input types. The resulting type is usually a supertype * that encompasses the possible values of the input types * * Examples: * widen('integer', 'rational') => 'rational' * widen('number', 'complex') => 'complex' * widen('number', 'collection') => 'collection' * widen('number', 'value') => 'value' * widen('number', 'expression') => 'expression' * widen('number', 'string') => 'any' */ export declare function widen(...types: Readonly<Type>[]): Type; export declare function isSignatureType(type: Readonly<Type> | TypeString): type is FunctionSignature; export declare function functionSignature(type: Readonly<Type>): Type | undefined; export declare function functionResult(type: Readonly<Type>): Type | undefined; export declare function collectionElementType(type: Readonly<Type>): Type | undefined; export declare function isValidType(t: any): t is Readonly<Type>; /** * Add a `toString()` method to the type object */ export declare function makeType(type: Type): Readonly<Type>;