Bullet-proof TS even more
npm install ts-roidsBullet proof TypeScript even more.



bash
npm i -D ts-roids
``pnpm
`bash
pnpm i -D ts-roids
`Requires TypesScript
v5.0+Documentation
Checkout the full API reference for all usage examples with details.
#### Types
ExclusiveUnion - Creates a union type where each variant has its specific properties required, while other properties are optional.
* UniqueArray - Create unique array type from a given array type T, a set perse.
* Prune - Prune a type T by recursively omitting properties of type N (defaults to NotIncluded).
* PositiveRange - Represents a range of positive integers from N to M (inclusive), useful for enforcing numeric bounds.
* UnionToTuple - Converts a union type T into a tuple type, allowing for ordered access to the union's members.
* EnforcedString - Constructs a type that restricts a string based on three optional constraints:
a prefix, a substring (must be contained), and a suffix.
* FilledString - Error out on an empty ('') string.
* DeepToPrimitive - Recursively transforms an object type T into a type where all properties are replaced with their corresponding primitive types.
* Assign - Copies all enumerable own properties from one target object to a source array of objects.
* CapitalizeFirst - Capitalizes the first character of a string literal type while preserving the rest.
* Is - Checks if two types T and U are exactly identical and resolves to true or false at the type level.
* IsNot - Check if T and U are not the same.
* Paths.
* DeepAwaited - Recursively resolves all nested Promise types to their underlying value.
* Flip - Flips keys with values of an object type Obj.
* DeepImmutable - Recursively turns the proprties within a given object type T immutable, as in have all the properties with the readonly modifier.
* Deepmutable - Recursively mutates all the proprties within a given object type T, as in have all the properties without the readonly modifier.
* DeepRequired - Recursively make all object properties required.
* DeepNotRequired - Recursively make all object properties not required.
* DeepOmit - Recursively omits specified nested properties from an object, based on a given predicate P.
* DeepPick - Deeply pick properties from a nested object, based on a given predicate P.
* EmptyObject - Represents any non-nullish value, basically {}.
* EqualStrlen - Check if two strings S1 and S2 have the same length.
* Strlen - Computes the length of a string S at the type level.
* StrMin - Enforces that a string S has a length greater than or equal to Min, returning a Message on violation.
* StrMax - Enforces that a string S has a length less than or equal to Max, returning a Message on violation.
* StrBetween - Ensures a string S has a length within [Min, Max], inclusive, returning a Message if outside the range.
* PartialExcept - Makes all properties in T optional except those in K which remain required.
* FilterBy - Filters keys from the object type Obj based on a specified predicate P.
* Float - Type representing a float.
* If - If C evaluates true, Do, otherwise return Else.
* IfEquals - Checks if type T is equal to type P. If T is equal to P, the type resolves to Do, otherwise Else.
* IfExtends - Checks if type T extends type P. if it does, the type resolves to Do, otherwise Else.
* ImmutableKeys - Retrieves the keys that are immutable (readonly) from an object of type Obj.
* Integer - Represents an integer.
* Abs - Get the absolute value of a Numeric.
* And - Logical AND between two boolean types.
* EitherOneOrMany - Represents a type that can be either a single value of type T or an array of values of type T.
* Nullable - Represents any non-nullish value, basically {}.
* Equals - Checks if two types X and Y are exactly equal.
* EvenNumeric - Represents an even Numeric.
* ExcludeNull - Excludes null from a type T.
* ExcludeNullable - Excludes Nullable from a type T.
* ExcludeUndefined - Excludes undefined from a type T.
* KeysOfUnion - Extracts the union of keys from a given union of object types, useful for accessing all possible keys in unions.
* Simplify - Flattens the structure of a type by resolving intersections and simplifying nested mapped types, enhancing readability.
* Extends - Evaluates whether one type T is assignable to another type U.
* Falsy - Represents a type that is falsy JavaScript.
* FalsyProperties - Extracts falsy properties from an object type T.
* IsArrayIncludesTypeof - Checks if an array type Arr includes one or more of T type.
* LastElement - Get the last element of the array.
* IsBigInt - Checks if T is a bigint.
* IsBoolean - Checks if T is a boolean.
* IsDeepImmutable - Checks if all the nested properties of a given object Obj are immutable.
* IsDeepMutable - Checks if all the nested properties of a given object Obj are mutable.
* IsDeepNotRequired - Checks if all the properties of a given object (nested) are not required, as in, all properties have the ? modifier.
* IsDeepRequired - Checks if all the properties of a given object (nested) are required, as in, all properties do not have the ? modifier.
* IsExactlyAny - Checks if a type T is exactly any.
* IsExactlyBigInt - Checks if a type T is exactly bigint not a subtype of it.
* IsExactlyNumber - Checks if a type T is exactly number not a subtype of it.
* IsExactlyString - Checks if a type T is exactly string not a subtype of it.
* IsExactlySymbol - Checks if a type T is exactly symbol not a subtype of it.
* IsExactlyUnknown - Checks if a type T is exactly unknown not a subtype of it.
* IsFalsy - Checks if a given type T is Falsy.
* IsFloat - Checks if a given type T is a Float.
* IsFunction - Checks if a given type T is a function.
* IsInteger - Checks if a given Numeric is an Integer.
* IsNever - Checks if a type T does not resolve, so never.
* IsNewable - Checks if a type T is Newable.
* IsNullable - Checks if a type T is Nullable.
* IsNumber - Checks if a type T is a number.
* IsNumeric - Checks if a type T is Numeric.
* IsObject - Checks if a given type T qualifies as an object.
* IsString - Check if a given type T is a string.
* IsSymbol - Check if a given type T is a symbol.
* IsTruthy - Check if a given type T resolves to a truthy value.
* Keys - Retrieves the union type of keys (property names) of a type T.
* Maybe - Type that might be Nullable
* MaybeUndefined - Type that might undefined.
* MutableKeys - Retrieves the keys that are mutable from an object of type Obj.
* Nand - Logical NAND between two boolean types B1 and B2.
* NegativeFloat - Represents a negative (]-∞, 0) [Float.
* NegativeFloatString - Represents a negative Float parsed from a string.
* NegativeInteger - Represents a negative (]-∞, 0) [Integer.
* NegativeIntegerString - Represents a negative Integer parsed from a string.
* NewType - Represents a new unique type derived from an existing base type. (branded type)
* Newable - Represents constructor functions that can be invoked using the new keyword.
* NonRequiredKeys - Returns all non required keys of an object Obj, as in any property of an object that is marked with ? operator.
* Not - Negates a boolean type B.
* Nullable - Represents a type that can either be null or undefined.
* Numeric - Represents a type that can either be number or bigint.
* NumerifyString - Turn a given string literal to a Numeric, if possible.
* Methods - Get the literal names of keys that are methods in an object type Obj.
* Properties - Get the literal names of keys that are properties in an object type Obj.
* OddNumeric - Represents an odd Numeric.
* OmitByType - Get a set of properties from Obj whose type are not assignable to T.
* OmitCommonKeys - Omit any common key between the the two objects,.
* OmitExactlyByType - Omit properties from Obj whose type exactly matches T.
* Optional - Represents a type that may be null, similar to Python's Optional type and Rust's Option enum.
* NotAssignableTo - Represents a type that excludes all members of U that are assignable to V.
* Or - Logical OR between two boolean types B1 and B2.
* PickByType - Pick from Obj a set of properties that match the type T.
* PickCommonKeys - Get the common keys between two objects.
* PickExactlyByType - Get a set of properties from Obj whose type exactly matches T.
* PositiveFloat - Represents a positive (0, +∞[) [Float.
* PositiveFloatString - Represents a positive Float parsed from a string.
* PositiveInteger - Represents a positive (0, +∞[) [Integer.
* PositiveIntegerString - Represents a negative Integer parsed from a string.
* Primitive - All primitive types.
* ReplaceKeys - Constructs a new type by replacing properties P of type Obj with object type Obj2.
* RequiredKeys - Get the required keys of an object (shallow).
* SizedTuple - Creates a tuple with a specific length, where each element is of a given type.
* StringEndsWith - Checks if a string S ends with E
* StringStartsWith - Checks if a string S starts with St
* StringifyPrimitive - Turns a given Primitive value (except symbol) into its string representation.Strlen
* - Get the length of a string S.TestType
* - Tests if type T1 and T2 are the same.TruthyProperties
* - Extracts truthy properties from an object type T.UnionToIntersection
* - As the name implies, it turns a union into an intersection.Vals
* - Get the set of type values in a given object.Xor
* - Exclusive OR between two boolean types B1 and B2.Xnor
* - Exclusive XNOR between two boolean types B1 and B2`.
The best way to understand how these types work is to check the tests directory. Each type has corresponding ~~edge~~ test cases that demonstrate its usage and expected behavior.
See releases.