<A extends AST>(ast: A): AStrips all encoding transformations from an AST, returning the decoded (type-level) representation.
Details
- Memoized: same input reference → same output reference.
- Recursively walks into composite nodes (Arrays, Objects, Union, Suspend).
Example (Getting the type AST)
import { Schema, SchemaAST } from "effect"
const schema = Schema.NumberFromString
const typeAst = SchemaAST.toType(schema.ast)
console.log(typeAst._tag) // "Number"export const const toType: <A extends AST>(ast: A) => AStrips all encoding transformations from an AST, returning the decoded
(type-level) representation.
Details
- Memoized: same input reference → same output reference.
- Recursively walks into composite nodes (
Arrays
,
Objects
,
Example (Getting the type AST)
import { Schema, SchemaAST } from "effect"
const schema = Schema.NumberFromString
const typeAst = SchemaAST.toType(schema.ast)
console.log(typeAst._tag) // "Number"
toType = memoize<A, A>(f: (a: A) => A): <A extends AST>(ast: A) => ACreates a memoized function whose input is an object, caching results by
object identity.
When to use
Use to reuse the result of a synchronous computation whose output is stable
for a given object reference.
Details
Each memoized wrapper owns a private WeakMap keyed by object identity.
Cached undefined results are still returned because the cache is checked
with WeakMap.has.
Gotchas
Structurally equal objects do not share cache entries. If the same object is
mutated after its first call, later calls still return the cached result for
that reference.
memoize(<function (type parameter) A in <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 <A extends AST>(ast: A): AA): function (type parameter) A in <A extends AST>(ast: A): AA => {
if (ast: ASTast.Base.encoding: Encoding | undefinedencoding) {
return const toType: <A extends AST>(ast: A) => AStrips all encoding transformations from an AST, returning the decoded
(type-level) representation.
Details
- Memoized: same input reference → same output reference.
- Recursively walks into composite nodes (
Arrays
,
Objects
,
Example (Getting the type AST)
import { Schema, SchemaAST } from "effect"
const schema = Schema.NumberFromString
const typeAst = SchemaAST.toType(schema.ast)
console.log(typeAst._tag) // "Number"
toType(function replaceEncoding<A extends AST>(
ast: A,
encoding: Encoding | undefined
): A
replaceEncoding(ast: A extends ASTast, var undefinedundefined))
}
const const out: anyout: any = ast: ASTast
const const type: anytype = const out: anyout.recur?.(const toType: <A extends AST>(ast: A) => AStrips all encoding transformations from an AST, returning the decoded
(type-level) representation.
Details
- Memoized: same input reference → same output reference.
- Recursively walks into composite nodes (
Arrays
,
Objects
,
Example (Getting the type AST)
import { Schema, SchemaAST } from "effect"
const schema = Schema.NumberFromString
const typeAst = SchemaAST.toType(schema.ast)
console.log(typeAst._tag) // "Number"
toType) ?? const out: anyout
const const encodingChecks: anyencodingChecks = const type: anytype.encodingChecks
if (const encodingChecks: anyencodingChecks) {
return function modifyOwnPropertyDescriptors<
A extends AST
>(
ast: A,
f: (d: {
[P in keyof A]: TypedPropertyDescriptor<A[P]>
}) => void
): A
modifyOwnPropertyDescriptors(const type: anytype, (d: {
[x: string]: TypedPropertyDescriptor<any>
}
d) => {
d: {
[x: string]: TypedPropertyDescriptor<any>
}
d.TypedPropertyDescriptor<any>encodingChecks.TypedPropertyDescriptor<any>.value?: anyvalue = var undefinedundefined
if (const type: anytype === ast: A extends ASTast) {
d: {
[x: string]: TypedPropertyDescriptor<any>
}
d.TypedPropertyDescriptor<any>checks.TypedPropertyDescriptor<any>.value?: anyvalue = function combineChecks(
a: Checks | undefined,
b: Checks | undefined
): Checks | undefined
combineChecks(const type: anytype.checks, const encodingChecks: anyencodingChecks)
}
})
}
return const type: anytype
})