interface Deep.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
| Name | Description |
|---|---|
| T | the target type |
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.
getAtWithpath.Definition
getAtWith<P extends Path.Get<T>>(path: P): (source: T) => Path.Result<T, P>;
Type parameters
| Name | Constraints | Description |
|---|---|---|
| P | Path.Get<T> | a Path in object type T |
Parameters
| Name | Type | Description |
|---|---|---|
path | P | the path into the object |
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.
matchAtWithvalue 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
| Name | Constraints | Description |
|---|---|---|
| P | Path.Get<T> | the string literal path type in the object |
Parameters
| Name | Type | Description |
|---|---|---|
path | P | the string path in the object |
matcher | Match<Path.Result<T, P>> | a matcher object that matches input values. |
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.
matchWithvalue with the given matcher.patchAtWith
Returns a function that patches a given value with the given patchItems at the given path.
patchAtWithvalue 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
| Name | Constraints | Default | Description |
|---|---|---|---|
| P | Path.Set<T> | the string literal path type in the object | |
| TT | T | utility type |
Parameters
| Name | Type | Description |
|---|---|---|
path | P | the string path in the object |
patchItem | Patch<Path.Result<T, P>, Path.Result<TT, P>> | the Patch definition to update the given value with |
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.
patchWithvalue with the given patchItems.Definition
patchWith<TE extends T = T, TT = T>(patchItem: Patch<TT, TE>): (source: TE) => T;
Type parameters
| Name | Constraints | Default | Description |
|---|---|---|---|
| TE | T | T | |
| TT | T | utility type |
Parameters
| Name | Type | Description |
|---|---|---|
patchItem | Patch<TT, TE> | the Patch definition to update the given value with |
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.
selectAtWithvalue 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
| Name | Constraints | Description |
|---|---|---|
| P | Path.Get<T> | the string literal path type in the object |
| SL | Selector<Path.Result<T, P>> | the selector shape type |
Parameters
| Name | Type | Description |
|---|---|---|
path | P | the string path in the object |
selector | Selector.Shape<SL> | a shape indicating the selection from the source values |
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.
selectWithvalue with the given selector.Definition
selectWith<SL extends Selector<T>>(selector: Selector.Shape<SL>): (source: T) => Selector.Result<T, SL>;
Type parameters
| Name | Constraints | Description |
|---|---|---|
| SL | Selector<T> | the selector shape type |
Parameters
| Name | Type | Description |
|---|---|---|
selector | Selector.Shape<SL> | a shape indicating the selection from the source values |
const value = { a: { b: 1, c: 'a' } };
const sel = Deep.withType<typeof value>().selectWith({ q: 'a.b' });
sel(value);
// => { q: 1 }