API Reference / @evolu/common / Type / TupleType

Interface: TupleType<Elements>

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

TupleType extends Type with an additional elements property for reflection.

Extends

  • Type<"Tuple", readonly [...{ [K in keyof Elements]: InferType<Elements[K]> }], readonly [...{ [K in keyof Elements]: InferInput<Elements[K]> }], TupleError<{ [K in keyof Elements]: InferError<Elements[K]> }[number]>, readonly [...{ [K in keyof Elements]: InferParent<Elements[K]> }], TupleError<{ [K in keyof Elements]: InferParentError<Elements[K]> }[number]>>

Type Parameters

Type Parameter
Elements extends readonly [AnyType, ...ReadonlyArray<AnyType>]

Properties

PropertyModifierTypeDescriptionInherited fromDefined in
[EvoluTypeSymbol]readonlytrue-Type.[EvoluTypeSymbol]packages/common/src/Type.ts:171
elementsreadonlyElements--packages/common/src/Type.ts:3252
ErrorpublicTupleError<{ [K in string | number | symbol]: InferError<Elements[K<K>]> }[number]>The specific error introduced by this Type. ### Example type StringError = typeof String.Error;Type.Errorpackages/common/src/Type.ts:96
Errorsreadonly| TupleError<{ [K in string | number | symbol]: InferError<Elements[K<K>]> }[number]> | TupleError<{ [K in string | number | symbol]: InferParentError<Elements[K<K>]> }[number]>ErrorParentError ### Example type StringParentErrors = typeof String.Errors;Type.Errors
fromreadonly(value) => Result<readonly [{ [K in string | number | symbol]: InferType<Elements[K<K>]> }], | TupleError<{ [K in string | number | symbol]: InferError<Elements[K<K>]> }[number]> | TupleError<{ [K in string | number | symbol]: InferParentError<Elements[K<K>]> }[number]>>Creates T from an Input value. This is useful when we have a typed value. from is a typed alias of fromUnknown.Type.frompackages/common/src/Type.ts:111
fromParentreadonly(value) => Result<readonly [{ [K in string | number | symbol]: InferType<Elements[K<K>]> }], TupleError<{ [K in string | number | symbol]: InferError<Elements[K<K>]> }[number]>>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.fromParentpackages/common/src/Type.ts:145
fromUnknownreadonly(value) => Result<readonly [{ [K in string | number | symbol]: InferType<Elements[K<K>]> }], | TupleError<{ [K in string | number | symbol]: InferError<Elements[K<K>]> }[number]> | TupleError<{ [K in string | number | symbol]: InferParentError<Elements[K<K>]> }[number]>>Creates T from an unknown value. This is useful when a value is unknown.Type.fromUnknownpackages/common/src/Type.ts:118
Inputpublicreadonly [{ [K in string | number | symbol]: InferInput<Elements[K<K>]> }]The type expected by from and fromUnknown. ### Example type StringInput = typeof String.Input;Type.Inputpackages/common/src/Type.ts:94
isreadonly(value) => value is readonly [{ [K in string | number | symbol]: InferType<Elements[K<K>]> }]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 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"]Type.ispackages/common/src/Type.ts:169
namereadonly"Tuple"-Type.namepackages/common/src/Type.ts:102
Parentpublicreadonly [{ [K in string | number | symbol]: InferParent<Elements[K<K>]> }]The parent type. ### Example type StringParent = typeof String.Parent;Type.Parentpackages/common/src/Type.ts:98
ParentErrorpublicTupleError<{ [K in string | number | symbol]: InferParentError<Elements[K<K>]> }[number]>The parent's error. ### Example type StringParentError = typeof String.ParentError;Type.ParentErrorpackages/common/src/Type.ts:100
toreadonly(value) => readonly [{ [K in string | number | symbol]: InferInput<Elements[K<K>]> }]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.topackages/common/src/Type.ts:127
toParentreadonly(value) => readonly [{ [K in string | number | symbol]: InferParent<Elements[K<K>]> }]The opposite of fromParent.Type.toParentpackages/common/src/Type.ts:148
Typereadonlyreadonly [{ [K in string | number | symbol]: InferType<Elements[K<K>]> }]The type this Type resolves to. ### Example type String = typeof String.Type;Type.Typepackages/common/src/Type.ts:182

Was this page helpful?