diff --git a/example/index.ts b/example/index.ts index 09e32442..87972843 100644 --- a/example/index.ts +++ b/example/index.ts @@ -6,21 +6,14 @@ import { Kind, TypeRegistry, FormatRegistry } from '@sinclair/typebox' const UnsafeByte = Type.Unsafe({ type: 'byte' }) const Byte = Type.Refine(UnsafeByte) - .Check((value) => typeof value === 'number') - .Check((value) => !isNaN(value), { message: 'Must not be NaN', x: 100 }) + .Check((value) => typeof value === 'number', { message: 'Expected number' }) + .Check((value) => !isNaN(value), { message: 'Expected non NaN number' }) .Check((value) => value >= 0, { message: 'Must be greater than 0' }) - .Check((value) => value < 256, { message: 'Must be something' }) + .Check((value) => value < 256, { message: 'Must be less than 256' }) .Done() -const A = Type.Object({ - x: Byte, - y: Byte, - z: Byte, -}) - -console.dir(A, { depth: 100 }) -console.log(TypeCompiler.Code(A)) -console.log(Value.Errors(Byte, 'asdsa').Take(10)) +const A = Type.Array(Byte) +console.log(Value.Errors(A, [0, 2, 3, 10000]).Take(10)) // Todo: Error Tests // Todo: Investigate Error Propogation for Refinements diff --git a/src/errors/errors.ts b/src/errors/errors.ts index 0f55bd36..cdc37382 100644 --- a/src/errors/errors.ts +++ b/src/errors/errors.ts @@ -76,7 +76,7 @@ import { IsArray, IsUint8Array, IsDate, IsPromise, IsFunction, IsAsyncIterator, // ------------------------------------------------------------------ // ValueGuard // ------------------------------------------------------------------ -import { IsRefine, IsUnknown } from '../type/guard/type' +import { IsRefine } from '../type/guard/type' // ------------------------------------------------------------------ // ValueErrorType // ------------------------------------------------------------------ @@ -199,7 +199,7 @@ export class ValueErrorIterator { // Create // -------------------------------------------------------------------------- function CreateRefinementError(schema: TSchema, refinement: Refinement, path: string, value: unknown): ValueError { - return { type: ValueErrorType.Refinement, schema, path, value, message: refinement.message || '' } + return { type: ValueErrorType.Refinement, schema, path, value, message: refinement.message } } function CreateError(errorType: ValueErrorType, schema: TSchema, path: string, value: unknown): ValueError { return { type: errorType, schema, path, value, message: GetErrorFunction()({ errorType, path, schema, value }) }