Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeBox resolver does not work with valid TypeBox schema #709

Closed
divmgl opened this issue Jul 31, 2024 · 6 comments
Closed

TypeBox resolver does not work with valid TypeBox schema #709

divmgl opened this issue Jul 31, 2024 · 6 comments

Comments

@divmgl
Copy link

divmgl commented Jul 31, 2024

Describe the bug
I'm getting this error:

Argument of type 'TObject<{ name: TString; score: TString; externalId: any; }>' is not assignable to parameter of type 'TObject<TProperties> | TypeCheck<TObject<TProperties>>'.ts(2345)
Argument of type 'TObject<{ name: TString; score: TString; externalId: any; }>' is not assignable to parameter of type 'TObject<TProperties> | TypeCheck<TObject<TProperties>>'.
  Type 'TObject<{ name: TString; score: TString; externalId: any; }>' is missing the following properties from type 'TypeCheck<TObject<TProperties>>': schema, references, checkFunc, code, and 3 more.ts(2345)

Here is the TypeBox schema:

export const UPDATE_APPLICATION_INPUT_SCHEMA = Type.Object({
  name: Type.String({ minLength: 1 }),
  score: Type.String(),
  externalId: Type.String().Nullable(),
})
  const form = useForm<UpdateApplicationInput>({
    resolver: typeboxResolver(UPDATE_APPLICATION_INPUT_SCHEMA),
    defaultValues: {
      name: application.name,
      externalId: application.externalId ?? null,
    },
  })

Why is this happening?

Expected behavior
No error occurs.

Additional context
TypeBox version: 0.32.35
@hookform/resolvers: 3.9.0

@divmgl
Copy link
Author

divmgl commented Jul 31, 2024

Also does not work with the new TypeCompiler.Compile. Could it be because of our TypeScript version? We're on 5.4.5.

@divmgl
Copy link
Author

divmgl commented Jul 31, 2024

@huynhducduy apologies for pinging you here. I see that you worked on this for 3.8.0. #674

Did you run into this during development? I'm thinking about switching my codebase over to TypeBox to overcome the Zod performance issues, but I'm running into this problem with @hookform/resolvers which is blocking the switch.

@huynhducduy
Copy link
Contributor

@divmgl can you first try to use it with @hookform/resolvers 3.7.0? and maybe with a newer typescript version too. Im using typescript 5.5.3 and it works just fine.

@divmgl
Copy link
Author

divmgl commented Jul 31, 2024

Hm, I wonder if this is a TypeBox problem.

Argument of type 'TObject<{ name: TString; groupId: TString; }>' is not assignable to parameter of type 'TObject<TProperties>'.
  Property '[Kind]' is missing in type 'TObject<{ name: TString; groupId: TString; }>' but required in type 'TObject<TProperties>'.ts(2345)
typebox.d.ts(240, 5): '[Kind]' is declared here.

This is happening in 3.7.0. Really strange.

@huynhducduy
Copy link
Contributor

I did not face any similar problems. Can you reproduce the error in a fresh source code?

@divmgl
Copy link
Author

divmgl commented Jul 31, 2024

I cleaned the repo and removed incremental build info files and things are working as expected now. Cheers.

@divmgl divmgl closed this as completed Jul 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants