Home > @infiniteobjects/type-utils
This library provides a collection of essential TypeScript types.
Type Alias | Description |
---|---|
AnyFunction | Matches any function |
Branded | A “branded type” is a primitive type with a compile-type key that makes it incompatible with other aliases for the primitive type. |
ClassConstructor | A constructor of classes of type T |
ConditionalExcept | Exclude keys from a shape that matches the given Condition . |
ConditionalKeys | Extract the keys from a type where the value type of the key extends the given Condition . |
ConditionalPick | Pick keys from the shape that matches the given Condition . |
Entries | A type to better handle Object.entries() types. |
Except | Create a type from an object type without certain keys. |
JsonArray | Matches a JSON array. |
Jsonify | <p>Transform a type to one that is assignable to the JsonValue type.</p><p>This includes: 1. Transforming JSON interface to a type that is assignable to JsonValue . 2. Transforming non-JSON value that is *jsonable* to a type that is assignable to JsonValue , where *jsonable* means the non-JSON value implements the .toJSON() method that returns a value that is assignable to JsonValue .</p> |
JsonObject | Matches a JSON object. |
JsonPrimitive | Matches any valid JSON primitive |
JsonValue | Matches any valid JSON value. |
MaybePromise | Type of the value wrapped by a Promise . |
Merge | Merge two types into a new type. Keys of the second type overrides keys of the first type. |
Nullable | Adds null to the type |
ObjectLike | Object like |
OptionalPropertyOf | Returns a type with all the optional properties of T |
PartialDeep | <p>Create a type from another type with all keys and nested keys set to optional.</p><p>Use-cases: - Merging a default settings/config object with another object, the second object would be a deep partial of the default object. - Mocking and testing complex entities, where populating an entire object with its keys would be redundant in terms of the mock or test.</p> |
Primitive | Matches any primitive value. https://developer.mozilla.org/en-US/docs/Glossary/Primitive |
ReadonlyDeep | Convert object s, Map s, Set s, and Array s and all of their keys/elements into immutable structures recursively. |
SetNonNullable | Makes all the properties of T not nullable |
SetNonNullableKeys | Create a type that makes the given keys notNullable. The remaining keys are kept as is. |
SetNullabeKeys | Creates a type with the specified keys set to Nullable. |
SetNullable | Makes all the properties of T nullable |
SetOptional | Create a type that makes the given keys optional. The remaining keys are kept as is. The sister of the SetRequired type. |
SetOptionalAsNullable | Sets the optional properties as null instead of undefined |
SetOptionalKeys | Create a type that makes the given keys optional. The remaining keys are kept as is. The sister of the SetRequired type. |
SetRequired | Create a type that makes the given keys required. The remaining keys are kept as is. The sister of the SetOptional type. |
SetTypeAs | Sets the type ‘OldType’ in ‘Base’ as type ‘NewType’ |
Simplify | Flatten the type output to improve type hints shown in editors. |