Skip to main content

interface WithType<T>

Typed and curried Deep API, used in situations where the target type is known but the value will be applied later.

Type parameters

NameDescription
Tthe target type
example
const s = { a: 1, b: { c: 'a', d: true }};
const upd = Deep.withType<typeof s>().patchWith([{ a: (v) => v + 1 }]);
upd(s);
// => { a: 2, b: { c: 'a', d: true }}

Methods

getAtWith

Returns a function that given an object returns the value at the given path.

Definition

getAtWith<P extends Path.Get<T>>(path: P): (source: T) => Path.Result<T, P>;

Type parameters

NameConstraintsDescription
PPath.Get<T>a Path in object type T

Parameters

NameTypeDescription
pathPthe path into the object
example
const value = { a: { b: { c: 5 } } }
const getValue = Deep.withType<typeof value>().getAtWith('a.b.c');
getValue(value);
// => 5

matchAtWith

Returns a function that matches a given value with the given matcher at the given string path.

Definition

matchAtWith<P extends Path.Get<T>>(path: P, matcher: Match<Path.Result<T, P>>): (source: T) => boolean;

Type parameters

NameConstraintsDescription
PPath.Get<T>the string literal path type in the object

Parameters

NameTypeDescription
pathPthe string path in the object
matcherMatch<Path.Result<T, P>>a matcher object that matches input values.
example
const items = [{ a: { b:  1, c: 'a' } }, { a: { b: 2, c: 'b' } }];
items.filter(Deep.matchAtWith('a.b', 2));
// => [{ a: 2, b: 'b' }]

matchWith

Returns a function that matches a given value with the given matcher.

Definition

matchWith(matcher: Match<T>): (source: T) => boolean;

Parameters

NameTypeDescription
matcherMatch<T>a matcher object that matches input values.
example
const value = { a: 1, b: 'a' };
const m = Deep.withType<typeof value>().matchWith({ a: 1 });
m(value);
// => true

patchAtWith

Returns a function that patches a given value with the given patchItems at the given path.

Definition

patchAtWith<P extends Path.Set<T>, TT = T>(path: P, patchItem: Patch<Path.Result<T, P>, Path.Result<TT, P>>): (source: T) => T;

Type parameters

NameConstraintsDefaultDescription
PPath.Set<T>the string literal path type in the object
TTTutility type

Parameters

NameTypeDescription
pathPthe string path in the object
patchItemPatch<Path.Result<T, P>, Path.Result<TT, P>>the Patch definition to update the given value with
example
const value = { a: { b: 1, c: 'a' } };
const upd = Deep.withType<typeof value>().patchAtWith('a', [{ b: (v) => v + 1 }])
upd(value);
// => { a: { b: 2, c: 'a' } }

patchWith

Returns a function that patches a given value with the given patchItems.

Definition

patchWith<TE extends T = T, TT = T>(patchItem: Patch<TT, TE>): (source: TE) => T;

Type parameters

NameConstraintsDefaultDescription
TETT
TTTutility type

Parameters

NameTypeDescription
patchItemPatch<TT, TE>the Patch definition to update the given value with
example
const value = { a: 1, b: 'a' };
const upd = Deep.withType<typeof value>().patch([{ a: v => v + 1 }]);
upd(value);
// => { a: 2, b: 'a' }

selectAtWith

Returns a function that selects a certain shape from a given value with the given selector at the given string path.

Definition

selectAtWith<P extends Path.Get<T>, SL extends Selector<Path.Result<T, P>>>(path: P, selector: Selector.Shape<SL>): (source: T) => Selector.Result<Path.Result<T, P>, SL>;

Type parameters

NameConstraintsDescription
PPath.Get<T>the string literal path type in the object
SLSelector<Path.Result<T, P>>the selector shape type

Parameters

NameTypeDescription
pathPthe string path in the object
selectorSelector.Shape<SL>a shape indicating the selection from the source values
example
const value = { a: { b: 1, c: 'a' } };
const sel = Deep.withType<typeof value>().selectAtWith('a', { q: 'b' });
sel(value);
// => { q: 1 }

selectWith

Returns a function that selects a certain shape from a given value with the given selector.

Definition

selectWith<SL extends Selector<T>>(selector: Selector.Shape<SL>): (source: T) => Selector.Result<T, SL>;

Type parameters

NameConstraintsDescription
SLSelector<T>the selector shape type

Parameters

NameTypeDescription
selectorSelector.Shape<SL>a shape indicating the selection from the source values
example
const value = { a: { b: 1, c: 'a' } };
const sel = Deep.withType<typeof value>().selectWith({ q: 'a.b' });
sel(value);
// => { q: 1 }