API Reference / @evolu/common / Type / TransformType
Interface: TransformType<FromType, ToType, TransformError>
Defined in: packages/common/src/Type.ts:1893
TransformType extends Type with additional fromType
and toType
properties for reflection.
Extends
Type
<"Transform"
,InferType
<ToType
>,InferInput
<FromType
>,TransformError
,InferType
<FromType
>,InferErrors
<FromType
>>
Type Parameters
Type Parameter | Default type |
---|---|
FromType extends AnyType | - |
ToType extends AnyType | - |
TransformError extends TypeError | never |
Properties
Property | Modifier | Type | Description | Overrides | Inherited from | Defined in |
---|---|---|---|---|---|---|
[EvoluTypeSymbol] | readonly | true | - | - | Type .[EvoluTypeSymbol] | packages/common/src/Type.ts:171 |
Error | public | TransformError | The specific error introduced by this Type. ### Example type StringError = typeof String.Error; | - | Type .Error | packages/common/src/Type.ts:96 |
Errors | readonly | | TransformError | InferErrors <FromType > | Error | ParentError ### Example type StringParentErrors = typeof String.Errors; | - | Type .Errors |
from | readonly | (value ) => Result <InferType <ToType >, | TransformError | InferErrors <FromType >> | Creates T from an Input value. This is useful when we have a typed value. from is a typed alias of fromUnknown . | - | Type .from | packages/common/src/Type.ts:111 |
fromParent | readonly | (value ) => [TransformError ] extends [never ] ? Ok <InferType <ToType >> : Result <InferType <ToType >, TransformError > | 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() | Type .fromParent | - | packages/common/src/Type.ts:1908 |
fromType | readonly | FromType | - | - | - | packages/common/src/Type.ts:1905 |
fromUnknown | readonly | (value ) => Result <InferType <ToType >, | TransformError | InferErrors <FromType >> | Creates T from an unknown value. This is useful when a value is unknown. | - | Type .fromUnknown | packages/common/src/Type.ts:118 |
Input | public | InferInput <FromType > | The type expected by from and fromUnknown . ### Example type StringInput = typeof String.Input; | - | Type .Input | packages/common/src/Type.ts:94 |
is | readonly | (value ) => value is InferType<ToType> | 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"] | - | Type .is | packages/common/src/Type.ts:169 |
name | readonly | "Transform" | - | - | Type .name | packages/common/src/Type.ts:102 |
Parent | public | InferType <FromType > | The parent type. ### Example type StringParent = typeof String.Parent; | - | Type .Parent | packages/common/src/Type.ts:98 |
ParentError | public | InferErrors <FromType > | The parent's error. ### Example type StringParentError = typeof String.ParentError; | - | Type .ParentError | packages/common/src/Type.ts:100 |
to | readonly | (value ) => InferInput | 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. | - | Type .to | packages/common/src/Type.ts:127 |
toParent | readonly | (value ) => InferType | The opposite of fromParent . | - | Type .toParent | packages/common/src/Type.ts:148 |
toType | readonly | ToType | - | - | - | packages/common/src/Type.ts:1906 |
Type | readonly | InferType | The type this Type resolves to. ### Example type String = typeof String.Type; | - | Type .Type | packages/common/src/Type.ts:182 |