API reference / @evolu/common / Type / TupleType
Interface: TupleType<Elements>
Defined in: packages/common/src/Type.ts:3320
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
| Property | Modifier | Type | Description | Inherited from | Defined in |
|---|---|---|---|---|---|
[EvoluTypeSymbol] | readonly | true | - | Type.[EvoluTypeSymbol] | packages/common/src/Type.ts:315 |
~standard | readonly | Props<readonly [{ [K in string | number | symbol]: InferInput<Elements[K<K>]> }], readonly [{ [K in string | number | symbol]: InferType<Elements[K<K>]> }]> | The Standard Schema properties. | Type.~standard | packages/common/src/Type.ts:4216 |
elements | readonly | Elements | - | - | packages/common/src/Type.ts:3330 |
Error | public | TupleError<{ [K in string | number | symbol]: InferError<Elements[K<K>]> }[number]> | The specific error introduced by this Type. ### Example type StringError = typeof String.Error; | Type.Error | packages/common/src/Type.ts:197 |
Errors | readonly | | TupleError<{ [K in string | number | symbol]: InferError<Elements[K<K>]> }[number]> | TupleError<{ [K in string | number | symbol]: InferParentError<Elements[K<K>]> }[number]> | Error / ParentError ### Example type StringParentErrors = typeof String.Errors; | Type.Errors | packages/common/src/Type.ts:381 |
from | readonly | (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.from | packages/common/src/Type.ts:212 |
fromParent | readonly | (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 when we have already partially validated value. | Type.fromParent | packages/common/src/Type.ts:292 |
fromUnknown | readonly | (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.fromUnknown | packages/common/src/Type.ts:284 |
Input | public | readonly [{ [K in string | number | symbol]: InferInput<Elements[K<K>]> }] | The type expected by from and fromUnknown. ### Example type StringInput = typeof String.Input; | Type.Input | packages/common/src/Type.ts:195 |
is | readonly | (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.is | packages/common/src/Type.ts:313 |
name | readonly | "Tuple" | - | Type.name | packages/common/src/Type.ts:203 |
orNull | readonly | (value) => | readonly [{ [K in string | number | symbol]: InferType<Elements[K<K>]> }] | null | Creates T from an Input value, returning null if validation fails. This is a convenience method that combines from with getOrNull. When to use: - When you need to convert a validation result to a nullable value - When the error is not important and you just want the value or nothing - APIs that expect T or null ### Example // ✅ Good: Optional user input const age = PositiveInt.orNull(userInput); if (age != null) { console.log("Valid age:", age); } // ✅ Good: Default fallback const maxRetries = PositiveInt.orNull(config.retries) ?? 3; // ❌ Avoid: When you need to know why validation failed (use from instead) const result = PositiveInt.from(userInput); if (!result.ok) { console.error(formatPositiveError(result.error)); } | Type.orNull | packages/common/src/Type.ts:277 |
orThrow | readonly | (value) => readonly [{ [K in string | number | symbol]: InferType<Elements[K<K>]> }] | Creates T from an Input value, throwing an error if validation fails. This is a convenience method that combines from with getOrThrow. When to use: - Configuration values that are guaranteed to be valid (e.g., hardcoded constants) - Application startup where failure should crash the program - Test code with known valid inputs ### Example // ✅ Good: Known valid constant const maxRetries = PositiveInt.orThrow(3); // ✅ Good: App configuration that should crash on invalid values const appName = SimpleName.orThrow("MyApp"); // ❌ Avoid: User input (use from instead) const userAge = PositiveInt.orThrow(userInput); // Could crash! // ✅ Better: Handle user input gracefully const ageResult = PositiveInt.from(userInput); if (!ageResult.ok) { // Handle validation error } | Type.orThrow | packages/common/src/Type.ts:245 |
Parent | public | readonly [{ [K in string | number | symbol]: InferParent<Elements[K<K>]> }] | The parent type. ### Example type StringParent = typeof String.Parent; | Type.Parent | packages/common/src/Type.ts:199 |
ParentError | public | TupleError<{ [K in string | number | symbol]: InferParentError<Elements[K<K>]> }[number]> | The parent's error. ### Example type StringParentError = typeof String.ParentError; | Type.ParentError | packages/common/src/Type.ts:201 |
Type | readonly | readonly [{ [K in string | number | symbol]: InferType<Elements[K<K>]> }] | The type this Type resolves to. ### Example type String = typeof String.Type; | Type.Type | packages/common/src/Type.ts:326 |