From d4e95a489d648ffd6f1a69c80cdbf54d06e0fcdd Mon Sep 17 00:00:00 2001 From: sinclair Date: Thu, 5 Dec 2024 14:20:03 +0900 Subject: [PATCH] TypeCheck Encode Inference and Schema and Reference Definition Order --- src/compiler/compiler.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/compiler/compiler.ts b/src/compiler/compiler.ts index 24a1cc4a..37726471 100644 --- a/src/compiler/compiler.ts +++ b/src/compiler/compiler.ts @@ -97,14 +97,6 @@ export class TypeCheck { public Code(): string { return this.code } - /** Returns an iterator for each error in this value. */ - public Errors(value: unknown): ValueErrorIterator { - return Errors(this.schema, this.references, value) - } - /** Returns true if the value matches the compiled type. */ - public Check(value: unknown): value is Static { - return this.checkFunc(value) - } /** Returns the schema type used to validate */ public Schema(): T { return this.schema @@ -113,13 +105,21 @@ export class TypeCheck { public References(): TSchema[] { return this.references } + /** Returns an iterator for each error in this value. */ + public Errors(value: unknown): ValueErrorIterator { + return Errors(this.schema, this.references, value) + } + /** Returns true if the value matches the compiled type. */ + public Check(value: unknown): value is Static { + return this.checkFunc(value) + } /** Decodes a value or throws if error */ public Decode, Result extends Static = Static>(value: unknown): Result { if (!this.checkFunc(value)) throw new TransformDecodeCheckError(this.schema, value, this.Errors(value).First()!) return (this.hasTransform ? TransformDecode(this.schema, this.references, value) : value) as never } /** Encodes a value or throws if error */ - public Encode, Result extends Static = Static>(value: unknown): Result { + public Encode, Result extends Static = Static>(value: unknown): Result { const encoded = this.hasTransform ? TransformEncode(this.schema, this.references, value) : value if (!this.checkFunc(encoded)) throw new TransformEncodeCheckError(this.schema, value, this.Errors(value).First()!) return encoded as never