UNPKG

@excentone/spfx-value-types

Version:

Contain common value types used when developing SharePoint Framework (SPFx) Web components.

23 lines (22 loc) 1.08 kB
/** * The primitive types in javascript. `undefined` and `null` data type were not included by purpose. */ export declare type PrimitiveType = number | string | boolean | bigint | symbol; /** * Infers the underlying primitive type of {@link ValueObject}. */ export declare type ValueObjectPrimitiveType<T> = T extends ValueObject<infer TPrimitive> ? TPrimitive : never; /** * Represents either the {@link ValueObject} specified in {@link TValueObject} or the underlying {@link PrimitiveType}. */ export declare type ValueObjectOrPrimitiveType<TValueObject extends ValueObject<PrimitiveType>> = TValueObject | ValueObjectPrimitiveType<TValueObject>; export declare abstract class ValueObject<T extends PrimitiveType> { protected readonly value: T; protected constructor(value: T); /** Validates the value object. Called in the constructor. */ protected abstract validate(): void; /** Returns the string representation of the value object. */ toString: () => string; /** Returns the underlying value of the value object. */ valueOf: () => T; }