Home > @skunkteam/types > BaseTypeImpl > extendWith
Extend the Type with additional static methods and properties.
Signature:
extendWith<const E>(factory: (type: this) => E): this & E;
Parameter | Type | Description |
---|---|---|
factory | (type: this) => E |
Returns:
this & E
Can be used to provide Type-specific utilities, nicely namespaced.
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());