AOT compiling with errors messages #797
-
Is it possible to use the AOT code and check for errors? It doesn't look like TypeCompiler.Code() creates an error function. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
@maemigh Hi,
Not at this stage. Currently the AOT option will generate a AOT Dynamic
import { TypeCompiler, TypeCheck } from 'npm:@sinclair/typebox/compiler'
import { Type, TSchema } from 'npm:@sinclair/typebox'
// (Deno | Browser) Needs ESM + URL.createObjectURL() cache support
export async function DynamicCompile<T extends TSchema>(schema: T, references: TSchema[] = []): Promise<TypeCheck<T>> {
const code = `export const T = (function () {${TypeCompiler.Code(schema, references)}})()`
const url = URL.createObjectURL(new Blob([code], { type: 'application/javascript' }))
return new TypeCheck(schema, references, (await import(url)).T, code)
}
const C = await DynamicCompile(Type.Object({
x: Type.Number(),
y: Type.Number(),
z: Type.Number(),
}))
const R = C.Decode({ x: 1, y: 2, z: 3 }) At this stage, the AOT and JIT still depend on dynamic introspection for fail cases (which includes Errors) and as of today, is not part of the compiler code gen infrastructure, but it may be in future (once dynamic API's have stabilized). So, if you are using Hope this helps |
Beta Was this translation helpful? Give feedback.
@maemigh Hi,
Not at this stage. Currently the AOT option will generate a
Check
function that returns a boolean result only. Note that JIT option also only generates the sameCheck
(with the Errors obtained through dynamic introspection (the same asValue.Errors()
)). The current AOT implementation in TypeBox was mostly written to try and accelerate the Check phase in eval restricted environments, using non-eval techniques like the following....AOT Dynamic