API reference / @evolu/common / Type / Type

Interface: Type<Name, T, Input, Error, Parent, ParentError>

Defined in: packages/common/src/Type.ts:86

Extended by

Type Parameters

Type ParameterDefault type
Name extends TypeName-
T-
Input-
Error extends TypeErrornever
ParentT
ParentError extends TypeErrorError

Properties

PropertyModifierTypeDescriptionDefined in
[EvoluTypeSymbol]readonlytrue-packages/common/src/Type.ts:168
ErrorpublicErrorThe specific error introduced by this Type. ### Example type StringError = typeof String.Error;packages/common/src/Type.ts:93
ErrorsreadonlyError | ParentErrorErrorParentError ### Example type StringParentErrors = typeof String.Errors;
fromreadonly(value) => Result<T, Error | ParentError>Creates T from an Input value. This is useful when we have a typed value. from is a typed alias of fromUnknown.packages/common/src/Type.ts:108
fromParentreadonly(value) => Result<T, Error>Creates T from Parent type. This function skips parent Types validations/transformations when we have already partially validated/transformed value. For example, TrimString.from checks whether a value is a string and trims it. If we only want to trim a string, we can use fromParent. ### Example // string & Brand<"Trimmed"> const value = TrimString.fromParent("a ").value; // as efficient as foo.trim()packages/common/src/Type.ts:142
fromUnknownreadonly(value) => Result<T, Error | ParentError>Creates T from an unknown value. This is useful when a value is unknown.packages/common/src/Type.ts:115
InputpublicInputThe type expected by from and fromUnknown. ### Example type StringInput = typeof String.Input;packages/common/src/Type.ts:91
isreadonly(value) => value is TA type guard that checks whether an unknown value satisfies the Type. ### Example const value: unknown = "hello"; if (String.is(value)) { // TypeScript now knows valueis astring here. console.log("This is a valid string!"); } const strings: unknown[] = [1, "hello", true, "world"]; const filteredStrings = strings.filter(String.is); console.log(filteredStrings); // ["hello", "world"]packages/common/src/Type.ts:166
namereadonlyName-packages/common/src/Type.ts:99
ParentpublicParentThe parent type. ### Example type StringParent = typeof String.Parent;packages/common/src/Type.ts:95
ParentErrorpublicParentErrorThe parent's error. ### Example type StringParentError = typeof String.ParentError;packages/common/src/Type.ts:97
toreadonly(value) => InputThe opposite of from and fromUnknown. This is useful to transform T back to its Input representation. For refine, it only removes the brand. For transform, it changes value.packages/common/src/Type.ts:124
toParentreadonly(value) => ParentThe opposite of fromParent.packages/common/src/Type.ts:145
TypereadonlyTThe type this Type resolves to. ### Example type String = typeof String.Type;packages/common/src/Type.ts:179

Was this page helpful?