npm
npm i -D typyxpnpm
pnpm i -D typyxRequires TypeScript v5.0+.
Check out the full API reference for detailed usage examples and docs.
Assign<Obj, ObjArr>- Copies all enumerable own properties from one target object to a source array of objects.FilterBy<Obj, P>- Filters keys from the object typeObjbased on a specified predicateP.Flip<Obj>- Flips the keys and values of an object typeObj.ImmutableKeys<Obj>- Retrieves thereadonlykeys from an object typeObj.Keys<T>- Retrieves the union of keys of a typeT.KeysOfUnion<T>- Extracts the union of keys from a union of object types.KeysToValues<Obj>- Creates a reverse mapping from values to keys for a simple object type.MakeOptional<T, K>- Makes the specified keysKoptional while preserving the original modifiers of all other keys.MakeRequired<T, K>- Makes the specified keysKrequired while preserving the original modifiers of all other keys.Methods<Obj>- Gets the literal names of keys that are methods in an object typeObj.MutableKeys<Obj>- Retrieves the mutable keys from an object typeObj.NonRequiredKeys<Obj>- Returns all non-required keys of an object typeObj.NotIncluded- Marker type used with deep pruning utilities to completely omit fields.OmitByType<Obj, T>- Omits properties fromObjwhose types are assignable toT.OmitCommonKeys<Obj1, Obj2>- Omits any keys shared byObj1andObj2.OmitExactlyByTypeDeep<Obj, T>- Deeply omits properties whose types exactly matchT.PickByType<Obj, T>- Picks properties fromObjwhose types are assignable toT.PickCommonKeys<Obj1, Obj2>- Gets the common keys between two object types.PickExactlyByType<Obj, T>- Picks properties fromObjwhose types exactly matchT.Properties<Obj>- Gets the literal names of keys that are non-method properties in an object typeObj.Prune<T, N = NotIncluded>- Recursively omits properties of typeNfromT.ReplaceKeys<Obj1, P, Obj2>- Replaces propertiesPinObj1with the corresponding properties fromObj2.RequiredKeys<Obj>- Gets the required keys of an object typeObj.Vals<Obj>- Gets the union of value types from an object type.
DeepAwaited<T>- Recursively resolves all nestedPromisetypes to their underlying values.DeepImmutable<Obj>- Recursively makes every property inObjreadonly.DeepMutable<Obj>- Recursively removesreadonlyfrom every property inObj.DeepNotRequired<Obj>- Recursively makes all properties optional.DeepOmit<Obj, P>- Recursively omits specified nested properties from an object based on pathP.DeepPick<Obj, P>- Deeply picks properties from a nested object based on pathP.DeepRequired<Obj>- Recursively makes all properties required.DeepToPrimitive<Obj>- Recursively transforms an object type into one whose properties are their primitive counterparts.IsDeepImmutable<Obj>- Checks if all nested properties ofObjare immutable.IsDeepMutable<Obj>- Checks if all nested properties ofObjare mutable.IsDeepNotRequired<Obj>- Checks if all nested properties ofObjare optional.IsDeepRequired<Obj>- Checks if all nested properties ofObjare required.Paths<Obj>- Generates all possible dot-separated key paths from a nested object type.
ExclusiveUnion<T>- Creates a union type where each variant keeps its own required properties while excluding incompatible ones.KeysOfUnion<T>- Extracts the full key union across a union of object types.NotAssignableTo<U, V>- Excludes all members ofUthat are assignable toV.TupleToUnion<T>- Converts a tuple type into a union type.UnionToIntersection<U>- Converts a union type into an intersection type.UnionToTuple<T>- Converts a union type into a tuple type.
Append<Arr, Item>- Adds an item to the end of a tuple.EitherOneOrMany<T>- Represents either a single value of typeTor an array ofT.Head<Arr>- Gets the first element of a tuple.IsArrayIncludesTypeof<Arr, T>- Checks whether an array typeArris assignable toT[].Last<Arr>- Gets the last element of a tuple.NonEmptyArray<T>- Represents an array containing at least one element of typeT.Pop<Arr>- Removes the last element of a tuple.Prepend<Arr, Item>- Adds an item to the start of a tuple.SizedTuple<T, N>- Creates a tuple of lengthNwhere each element is of typeT.Tail<Arr>- Removes the first element of a tuple.Tuple<T>- NarrowsTto a tuple type and rejects regular arrays.UniqueArray<T>- Creates a unique array type from an array typeT.Zip<L, L1>- Pairs elements from two tuples by index into a tuple of pairs.
CapitalizeFirst<T>- Capitalizes the first character of a string literal type.EnforcedString<Prefix, Contains, Suffix>- Restricts a string using optional prefix, substring, and suffix constraints.EqualStrlen<S1, S2>- Checks whether two strings have the same length.FilledString<S>- Errors on an empty string literal''.NumerifyString<S>- Converts a string literal into aNumericwhen possible.StringEndsWith<S, E>- Checks whether a stringSends withE.StringStartsWith<S, St>- Checks whether a stringSstarts withSt.StringifyPrimitive<P>- Turns a primitive value type into its string representation.StrBetween<S, Min, Max>- Ensures a stringShas a length within[Min, Max].Strlen<S>- Computes the length of a stringS.StrMax<S, Max>- Ensures that a stringShas length less than or equal toMax.StrMin<S, Min>- Ensures that a stringShas length greater than or equal toMin.
Abs<N>- Gets the absolute value of aNumeric.Even<T>- Represents an evenNumeric.Float<N>- Type representing a float.Integer<N>- Represents an integer.IsFloat<N>- Checks if a given numeric type is a float.IsInteger<N>- Checks if a given numeric type is an integer.IsNegative<N>- Checks if a numeric type is negative.IsNegativeFloat<N>- Checks if a numeric type is a negative float.IsNegativeInteger<N>- Checks if a numeric type is a negative integer.IsPositive<N>- Checks if a numeric type is positive.IsPositiveFloat<N>- Checks if a numeric type is a positive float.IsPositiveInteger<N>- Checks if a numeric type is a positive integer.NegativeFloat<N>- Represents a negativeFloat<N>.NegativeFloatString<S>- Represents a negative float parsed from a string.NegativeInteger<N>- Represents a negativeInteger<N>.NegativeIntegerString<S>- Represents a negative integer parsed from a string.Numeric- Representsnumber | bigint.Odd<T>- Represents an oddNumeric.PositiveFloat<N>- Represents a positiveFloat<N>.PositiveFloatString<S>- Represents a positive float parsed from a string.PositiveInteger<N>- Represents a positiveInteger<N>.PositiveIntegerString<S>- Represents a positive integer parsed from a string.PositiveRange<N, M>- Represents a range of positive integers fromNtoMinclusive.
And<B1, B2>- LogicalANDbetween two boolean types.Equals<X, Y>- Checks if two types are exactly equal.If<C, Do, Else>- Resolves toDoifCistrue, otherwiseElse.IfEquals<T, P, Do, Else>- Resolves toDoifTequalsP, otherwiseElse.IfExtends<T, P, Do, Else>- Resolves toDoifTextendsP, otherwiseElse.Nand<B1, B2>- LogicalNANDbetween two boolean types.Nor<A, B>- LogicalNORbetween two boolean types.Not<B>- Negates a boolean type.Or<B1, B2>- LogicalORbetween two boolean types.Xand<A, B>- LogicalXANDbetween two boolean types.Xnor<A, B>- LogicalXNORbetween two boolean types.Xor<B1, B2>- LogicalXORbetween two boolean types.
Extends<T, U>- Evaluates whether typeTis assignable to typeU.FalsyProperties<T>- Extracts falsy properties from an object typeT.Is<T, U>- Checks if two types are exactly identical.IsAnyFunction<T>- Checks ifTis an arbitrary function type.IsArray<T>- Checks ifTis an array type.IsBigInt<T>- Checks ifTis abigint.IsBoolean<T>- Checks ifTis aboolean.IsExactlyAny<T>- Checks ifTis exactlyany.IsExactlyBigInt<T>- Checks ifTis exactlybigint.IsExactlyNumber<T>- Checks ifTis exactlynumber.IsExactlyString<T>- Checks ifTis exactlystring.IsExactlySymbol<T>- Checks ifTis exactlysymbol.IsExactlyUnknown<T>- Checks ifTis exactlyunknown.IsFalsy<T>- Checks if a given typeTisFalsy.IsFunction<T>- Checks if a given typeTis a function.IsNever<T>- Checks if a type resolves tonever.IsNewable<T>- Checks if a typeTisNewable.IsNot<T, U>- Checks if two types are not identical.IsNullable<T>- Checks if a typeTisNullable.IsNumber<T>- Checks if a typeTis anumber.IsNumeric<T>- Checks if a typeTisNumeric.IsObject<T>- Checks if a typeTqualifies as an object.IsString<T>- Checks if a typeTis astring.IsSymbol<T>- Checks if a typeTis asymbol.IsTruthy<T>- Checks if a typeTresolves to a truthy value.IsUnknown<T>- Checks if a typeTis assignable tounknown.TestType<T1, T2, Expected>- Tests whetherT1andT2match the expected relationship.TruthyProperties<T>- Extracts truthy properties from an object typeT.
AnyFunction- Represents any function accepting any arguments and returning any value.EmptyObject- Represents a non-nullish object-like value.ExcludeNull<T>- Excludesnullfrom a typeT.ExcludeNullable<T>- ExcludesNullablefrom a typeT.ExcludeUndefined<T>- Excludesundefinedfrom a typeT.Falsy- Represents JavaScript falsy values.Maybe<T>- Represents a type that may beNullable.MaybeUndefined<T>- Represents a type that may beundefined.MaybeUnknown<T>- Represents a type widened withunknown.Message<T>- Used to surface readable error messages instead ofnever.Newable- Represents constructor functions that can be invoked withnew.NewType<New, Base>- Creates a branded type derived from an existing base type.Nullable- Represents a type that can benullorundefined.Optional<T>- Represents a type that may benull, similar to Python'sOptionalor Rust'sOption.PartialExcept<T, P>- Makes all properties inToptional except those inP, which remain required.Primitive- Represents all JavaScript primitive types.Simplify<T>- Flattens and normalizes a type for better readability.UnknownFunction- Represents a function acceptingunknownarguments and returningunknown.
The best way to understand how these types work is to check the tests directory.
See releases.
MIT © @rccyx