API reference / @evolu/common / Type / ObjectWithRecordType

Interface: ObjectWithRecordType<Props, KeyName, KeyT, KeyInput, KeyError, KeyParent, KeyParentError, Value>

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

ObjectWithRecordType extends Type with additional props and record properties for reflection.

Extends

Type Parameters

Type Parameter
Props extends Record<string, AnyType>
KeyName extends TypeName
KeyT extends string
KeyInput extends string
KeyError extends TypeError
KeyParent extends string
KeyParentError extends TypeError
Value extends AnyType

Properties

PropertyModifierTypeDescriptionInherited fromDefined in
[EvoluTypeSymbol]readonlytrue-Type.[EvoluTypeSymbol]packages/common/src/Type.ts:168
ErrorpublicObjectWithRecordError<{ [K in string | number | symbol]: InferError<Props[K]> }, KeyError, InferError<Value>>The specific error introduced by this Type. ### Example type StringError = typeof String.Error;Type.Errorpackages/common/src/Type.ts:93
Errorsreadonly| ObjectWithRecordError<{ [K in string | number | symbol]: InferError<Props[K]> }, KeyError, InferError<Value>> | ObjectWithRecordError<{ [K in string | number | symbol]: InferParentError<Props[K]> }, KeyParentError, InferParentError<Value>>ErrorParentError ### Example type StringParentErrors = typeof String.Errors;Type.Errors
fromreadonly(value) => Result<Readonly<DrainOuterGeneric<{ [K in string | number | symbol]: ({ [K in string | number | symbol]: InferType<(...)[(...)]> } & { [K in string | number | symbol]?: (...) extends (...) ? (...) : (...) })[K] }>> & Readonly<Record<KeyT, InferType<Value>>>, | ObjectWithRecordError<{ [K in string | number | symbol]: InferError<Props[K]> }, KeyError, InferError<Value>> | ObjectWithRecordError<{ [K in string | number | symbol]: InferParentError<Props[K]> }, KeyParentError, InferParentError<Value>>>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:108
fromParentreadonly(value) => Result<Readonly<DrainOuterGeneric<{ [K in string | number | symbol]: ({ [K in string | number | symbol]: InferType<(...)[(...)]> } & { [K in string | number | symbol]?: (...) extends (...) ? (...) : (...) })[K] }>> & Readonly<Record<KeyT, InferType<Value>>>, ObjectWithRecordError<{ [K in string | number | symbol]: InferError<Props[K]> }, KeyError, InferError<Value>>>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:142
fromUnknownreadonly(value) => Result<Readonly<DrainOuterGeneric<{ [K in string | number | symbol]: ({ [K in string | number | symbol]: InferType<(...)[(...)]> } & { [K in string | number | symbol]?: (...) extends (...) ? (...) : (...) })[K] }>> & Readonly<Record<KeyT, InferType<Value>>>, | ObjectWithRecordError<{ [K in string | number | symbol]: InferError<Props[K]> }, KeyError, InferError<Value>> | ObjectWithRecordError<{ [K in string | number | symbol]: InferParentError<Props[K]> }, KeyParentError, InferParentError<Value>>>Creates T from an unknown value. This is useful when a value is unknown.Type.fromUnknownpackages/common/src/Type.ts:115
InputpublicReadonly<DrainOuterGeneric<{ [K in string | number | symbol]: ({ [K in string | number | symbol]: InferInput<Props[K]> } & { [K in string | number | symbol]?: Props[K] extends OptionalType<U> ? InferInput<U> : never })[K] }>> & Readonly<Record<KeyInput, InferInput<Value>>>The type expected by from and fromUnknown. ### Example type StringInput = typeof String.Input;Type.Inputpackages/common/src/Type.ts:91
isreadonly(value) => value is Readonly<DrainOuterGeneric<{ [K in string | number | symbol]: ({ [K in string | number | symbol]: InferType<Props[K]> } & { [K in string | number | symbol]?: (...)[(...)] extends OptionalType<(...)> ? InferType<(...)> : never })[K] }>> & Readonly<Record<KeyT, InferType<Value>>>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:166
namereadonly"ObjectWithRecord"-Type.namepackages/common/src/Type.ts:99
ParentpublicReadonly<DrainOuterGeneric<{ [K in string | number | symbol]: ({ [K in string | number | symbol]: InferParent<Props[K]> } & { [K in string | number | symbol]?: Props[K] extends OptionalType<U> ? InferParent<U> : never })[K] }>> & Readonly<Record<KeyParent, InferParent<Value>>>The parent type. ### Example type StringParent = typeof String.Parent;Type.Parentpackages/common/src/Type.ts:95
ParentErrorpublicObjectWithRecordError<{ [K in string | number | symbol]: InferParentError<Props[K]> }, KeyParentError, InferParentError<Value>>The parent's error. ### Example type StringParentError = typeof String.ParentError;Type.ParentErrorpackages/common/src/Type.ts:97
propsreadonlyProps--packages/common/src/Type.ts:2867
recordreadonlyRecordType<KeyName, KeyT, KeyInput, KeyError, KeyParent, KeyParentError, Value>--packages/common/src/Type.ts:2868
toreadonly(value) => Readonly<DrainOuterGeneric<{ [K in string | number | symbol]: ({ [K in string | number | symbol]: InferInput<Props[K]> } & { [K in string | number | symbol]?: (...)[(...)] extends OptionalType<(...)> ? InferInput<(...)> : never })[K] }>> & Readonly<Record<KeyInput, InferInput<Value>>>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:124
toParentreadonly(value) => Readonly<DrainOuterGeneric<{ [K in string | number | symbol]: ({ [K in string | number | symbol]: InferParent<Props[K]> } & { [K in string | number | symbol]?: (...)[(...)] extends OptionalType<(...)> ? InferParent<(...)> : never })[K] }>> & Readonly<Record<KeyParent, InferParent<Value>>>The opposite of fromParent.Type.toParentpackages/common/src/Type.ts:145
TypereadonlyReadonly<DrainOuterGeneric<{ [K in string | number | symbol]: ({ [K in string | number | symbol]: InferType<Props[K]> } & { [K in string | number | symbol]?: Props[K] extends OptionalType<U> ? InferType<U> : never })[K] }>> & Readonly<Record<KeyT, InferType<Value>>>The type this Type resolves to. ### Example type String = typeof String.Type;Type.Typepackages/common/src/Type.ts:179

Was this page helpful?