A safer variant for defining a type for a sub-set of object keys.
Given a following interface:
interface Person {
name: string;
age: number;
title: string;
}
a type for any key of that interface would be:
type PersonKey = keyof Person;
For a subset of keys you would do this:
type ModifiableKey = 'name' | 'title';
However that doesn't provide any immediate validation that name and title are in fact keys of the Person interface.
The KeyOf helper resolves this:
type ModifiableKey1 = KeyOf<Person, 'name' | 'title'>; // all OK
type ModifiableKey2 = KeyOf<Person, 'name' | 'title' | 'citizenship'>; // TS2344: Type '"name" | "title" | "citizenship"' does not satisfy...
record containing the properties
selected key(s) of R
Helper type for extending a type with | null | undefined.
the raw type to be extended
Checks whether the arrays are shallowly equal.
type of both arrays
first array to compare
second array to compare
Checks whether the values are shallowly equal. Supports primitives, arrays and objects.
type of both objects
first value to compare
second value to compare
Merges each index of an array separately, while keeping the original value if the new one is undefined.
Note that extra elements in the sparseArray are ignored.
Example:
const mergedArray = mergeArrays([1,2,3], [9,undefined,10])
// mergedArray === [9,2,10]
original tuple
new sparse array with undefined values as placeholders
Simulates latency by resolving the returned promise after randomly chosen delay constrained with minTimeout and maxTimeout.
minimum number of milliseconds to wait
maximum number of milliseconds to wait
this message when provided, will be logged into the console along with the actual delay
Simulates latency by resolving the returned promise after exactly timeout milliseconds.
number of milliseconds to wait
this message when provided, will be logged into the console along with the actual delay
Checks whether the valueOrFunction is a function.
type of the function
value that could be either a function of the specific type or any non-function value
An alternative to Boolean for usage in [].filter(). In addition to the actual filtering it also ensures
that the result of .filter() operation is typed properly - i.e. it skips false | null | undefined | '' | 0 from the input type.
type of the value
value that could eventually be falsy
Generated using TypeDoc
@spicy-hooks/utils
API reference
This is a detailed API reference of the
@spicy-hooks/utilspackage.For high-level information about this package and installation instructions, please see our GitHub repository.