Options
All
  • Public
  • Public/Protected
  • All
Menu

Class that represent the number approximation. It is basically a sum type (often cryptically called "discriminated union") with 3 options, determined by the property, set on the instance creation. See the percent, threshold and digits below.

The instances of this type are expected to be created with the static constructor method fromApproximation.

Hierarchy

  • Base
    • NumberApproximation

Index

Constructors

constructor

Properties

digits

digits: number = undefined

The number of digits after the point, which should be identical in the received and expected values, to consider them equal.

percent

percent: number = undefined

The number of percents (0 <= x <= 100) on which the provided value may differ from the expected value.

threshold

threshold: number = undefined

The exact threshold number on which the provided value may differ from the expected value.

Methods

initialize

  • initialize<T>(props?: Partial<T>): void
  • This method applies its 1st argument (if any) to the current instance using Object.assign().

    Supposed to be overridden in the subclasses to customize the instance creation process.

    Type parameters

    Parameters

    • Optional props: Partial<T>

    Returns void

Static fromApproximation

Static maybeNew

  • maybeNew<T>(props?: InstanceType<T> | Partial<InstanceType<T>>): InstanceType<T>
  • This is a type-safe static constructor method, accepting a single argument. If that argument is already an instance of this class - it is returned right away, otherwise the new constructor is used for instantiation.

    Type parameters

    Parameters

    • Optional props: InstanceType<T> | Partial<InstanceType<T>>

    Returns InstanceType<T>

Static new

  • new<T>(props?: Partial<InstanceType<T>>): InstanceType<T>
  • This is a type-safe static constructor method, accepting a single argument, with the object, corresponding to the class properties. It will generate a compilation error, if unknown property is provided.

    For example:

    class MyClass extends Base {
    prop : string
    }

    const instance : MyClass = MyClass.new({ prop : 'prop', wrong : 11 })

    will produce:

    TS2345: Argument of type '{ prop: string; wrong: number; }' is not assignable to parameter of type 'Partial<MyClass>'.
    Object literal may only specify known properties, and 'wrong' does not exist in type 'Partial<MyClass>'

    The only thing this constructor does is create an instance and call the initialize method on it, forwarding the first argument. The customization of instance is supposed to be performed in that method.

    Type parameters

    Parameters

    • Optional props: Partial<InstanceType<T>>

    Returns InstanceType<T>

Generated using TypeDoc