Thanks to visit codestin.com
Credit goes to github.com

Skip to content

TypeBox Adapter does not respect global settings (e.g. FormatRegistry) #65

@NiklasPor

Description

@NiklasPor

It seems like the TypeBox adapter is not respecting global settings. In my example I've got a simple email validator:

import { FormatRegistry } from "@sinclair/typebox";
FormatRegistry.Set("demo", () => true);

Now if you try to use it via TypeBox wrap:

import { Type } from "@sinclair/typebox";
import { wrap } from "@typeschema/typebox";

const schema = Type.String({ format: "demo" });
const wrapped = wrap(schema);
const result = wrapped.validate("test_string");

// Throws: "Unknown format 'email'"

My first suspicion would be that the dynamic import inside @typeschema/typebox conflicts with the global module configuration in my node application:

const importValidationModule = memoize(async () => {
  const {TypeCompiler} = await import('@sinclair/typebox/compiler');
  return {TypeCompiler};
});

Versions:

Node: 20
"@sinclair/typebox": "0.33.7",
"@typeschema/typebox": "0.13.4"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions