API reference / @evolu/common / Type / Type
Interface: Type<Name, T, Input, Error, Parent, ParentError>
Defined in: packages/common/src/Type.ts:86
Extended by
InstanceOfType
BrandType
IdType
LiteralType
TransformType
ArrayType
RecordType
ObjectType
ObjectWithRecordType
UnionType
RecursiveType
TupleType
OptionalType
Type Parameters
Type Parameter | Default type |
---|---|
Name extends TypeName | - |
T | - |
Input | - |
Error extends TypeError | never |
Parent | T |
ParentError extends TypeError | Error |
Properties
Property | Modifier | Type | Description | Defined in |
---|---|---|---|---|
[EvoluTypeSymbol] | readonly | true | - | packages/common/src/Type.ts:168 |
Error | public | Error | The specific error introduced by this Type. ### Example type StringError = typeof String.Error; | packages/common/src/Type.ts:93 |
Errors | readonly | Error | ParentError | Error | ParentError ### Example type StringParentErrors = typeof String.Errors; |
from | readonly | (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 |
fromParent | readonly | (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 |
fromUnknown | readonly | (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 |
Input | public | Input | The type expected by from and fromUnknown . ### Example type StringInput = typeof String.Input; | packages/common/src/Type.ts:91 |
is | readonly | (value ) => value is T | A type guard that checks whether an unknown value satisfies the Type. ### Example const value: unknown = "hello"; if (String.is(value)) { // TypeScript now knows valueis a string 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 |
name | readonly | Name | - | packages/common/src/Type.ts:99 |
Parent | public | Parent | The parent type. ### Example type StringParent = typeof String.Parent; | packages/common/src/Type.ts:95 |
ParentError | public | ParentError | The parent's error. ### Example type StringParentError = typeof String.ParentError; | packages/common/src/Type.ts:97 |
to | readonly | (value ) => Input | The 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 |
toParent | readonly | (value ) => Parent | The opposite of fromParent . | packages/common/src/Type.ts:145 |
Type | readonly | T | The type this Type resolves to. ### Example type String = typeof String.Type; | packages/common/src/Type.ts:179 |