<A extends AST>(ast: A): AMarks an AST node's property key as optional by setting
Context.isOptional to true.
Details
Also propagates the optional flag through the last link of the encoding chain if present.
export function function optionalKey<A extends AST>(
ast: A
): A
Marks an AST node's property key as optional by setting
Context.isOptional
to true.
Details
Also propagates the optional flag through the last link of the encoding
chain if present.
optionalKey<function (type parameter) A in optionalKey<A extends AST>(ast: A): AA extends type AST =
| Declaration
| Null
| Undefined
| Void
| Never
| Unknown
| Any
| String
| Number
| Boolean
| BigInt
| Symbol
| Literal
| UniqueSymbol
| ObjectKeyword
| Enum
| TemplateLiteral
| Arrays
| Objects
| Union<AST>
| Suspend
Discriminated union of all AST node types.
Details
Every Schema has an .ast property of this type. Use the guard functions
(
isString
,
isObjects
, etc.) to narrow to a specific variant,
then access variant-specific fields.
- All variants share the
Base
fields:
annotations, checks,
encoding, context.
- Discriminate on the
_tag field (e.g. "String", "Objects", "Union").
AST>(ast: A extends ASTast: function (type parameter) A in optionalKey<A extends AST>(ast: A): AA): function (type parameter) A in optionalKey<A extends AST>(ast: A): AA {
const const context: Contextconst context: {
isOptional: boolean;
isMutable: boolean;
defaultValue: Encoding | undefined;
annotations: Schema.Annotations.Key<unknown> | undefined;
}
context = ast: ASTast.Base.context: Context | undefinedcontext ?
ast: ASTast.Base.context: Context | undefined(property) Base.context: {
isOptional: boolean;
isMutable: boolean;
defaultValue: Encoding | undefined;
annotations: Schema.Annotations.Key<unknown> | undefined;
}
context.Context.isOptional: booleanisOptional === false ?
new constructor Context(isOptional: boolean, isMutable: boolean, defaultValue?: Encoding | undefined, annotations?: Schema.Annotations.Key<unknown> | undefined): ContextRepresents per-property metadata attached to AST nodes via
Base.context
.
Details
Tracks whether a property key is optional, mutable, has a constructor
default, or carries key-level annotations. Typically set by helpers like
optionalKey
and Schema.mutableKey.
isOptional — the property key may be absent from the input.
isMutable — the property is readonly when false.
defaultValue — an
Encoding
applied during construction to
supply missing values.
annotations — key-level annotations (e.g. description of the key
itself).
Context(true, ast: ASTast.Base.context: Context | undefined(property) Base.context: {
isOptional: boolean;
isMutable: boolean;
defaultValue: Encoding | undefined;
annotations: Schema.Annotations.Key<unknown> | undefined;
}
context.Context.isMutable: booleanisMutable, ast: ASTast.Base.context: Context | undefined(property) Base.context: {
isOptional: boolean;
isMutable: boolean;
defaultValue: Encoding | undefined;
annotations: Schema.Annotations.Key<unknown> | undefined;
}
context.Context.defaultValue: Encoding | undefinedUsed for constructor default values (e.g. withConstructorDefault API)
defaultValue, ast: ASTast.Base.context: Context | undefined(property) Base.context: {
isOptional: boolean;
isMutable: boolean;
defaultValue: Encoding | undefined;
annotations: Schema.Annotations.Key<unknown> | undefined;
}
context.Context.annotations: anyannotations) :
ast: ASTast.Base.context: Context | undefined(property) Base.context: {
isOptional: boolean;
isMutable: boolean;
defaultValue: Encoding | undefined;
annotations: Schema.Annotations.Key<unknown> | undefined;
}
context :
new constructor Context(isOptional: boolean, isMutable: boolean, defaultValue?: Encoding | undefined, annotations?: Schema.Annotations.Key<unknown> | undefined): ContextRepresents per-property metadata attached to AST nodes via
Base.context
.
Details
Tracks whether a property key is optional, mutable, has a constructor
default, or carries key-level annotations. Typically set by helpers like
optionalKey
and Schema.mutableKey.
isOptional — the property key may be absent from the input.
isMutable — the property is readonly when false.
defaultValue — an
Encoding
applied during construction to
supply missing values.
annotations — key-level annotations (e.g. description of the key
itself).
Context(true, false)
return const optionalKeyLastLink: <
A extends AST
>(
ast: A
) => A
optionalKeyLastLink(function replaceContext<A extends AST>(
ast: A,
context: Context | undefined
): A
replaceContext(ast: A extends ASTast, const context: Contextconst context: {
isOptional: boolean;
isMutable: boolean;
defaultValue: Encoding | undefined;
annotations: Schema.Annotations.Key<unknown> | undefined;
}
context))
}