Skip to content

Latest commit

 

History

History
38 lines (24 loc) · 981 Bytes

types.basetypeimpl.extendwith.md

File metadata and controls

38 lines (24 loc) · 981 Bytes

Home > @skunkteam/types > BaseTypeImpl > extendWith

BaseTypeImpl.extendWith() method

Extend the Type with additional static methods and properties.

Signature:

extendWith<const E>(factory: (type: this) => E): this & E;

Parameters

Parameter Type Description
factory (type: this) => E

Returns:

this & E

Remarks

Can be used to provide Type-specific utilities, nicely namespaced.

Example

const ISODate = string.withRegexpConstraint('ISODate', ISODateRE).extendWith(T => ({
    fromJS: (date: Date) => ISODate(formatISO(date)),
    toJS: (isoDate: The<typeof T>) => parseISO(isoDate),
}));

const now = ISODate.fromJS(new Date());