-
-
Notifications
You must be signed in to change notification settings - Fork 165
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
Type instantiation is excessively deep and possibly infinite. #24
Comments
Can you send me some code examples? |
I have created a repo with my code.
export const vIPage = merge([
vIPageOrDatabaseCommon,
object({
object: literal('page'),
parent: union([vIParentDatabase, vIParentPage, vIParentWorkspace]),
// properties: record(vIPageProp),
}),
]); |
Yes, the problem is |
I was able to reproduce the problem. However, I could not find the bug yet. I will investigate further in a moment. It is interesting to note that the problem does not occur in TypeScript v4.9.5. Therefore, it could also be a bug in TypeScript v5. import { merge, omit, object, union, transform, record, string } from "valibot";
const Merge1 = merge([object({}), object({ key: string() })]);
const Merge2 = merge([Merge1, object({})]);
const Object1 = merge([Merge2, object({})]);
const Object2 = merge([omit(Merge2, ["key"]), object({})]);
const Record = record(union([Object1, Object2]));
transform(Record, (a) => a); // Error: Type instantiation is excessively deep and possibly infinite.ts(2589) |
So as a workaround, you could downgrade TypeScript. It is important that you set the TypeScript version in VS Code to the version in your |
I have thoroughly checked the source code of Since I have similar problems with Modular Forms using TypeScript v5, I assume that it must be a bug in TypeScript. I can't explain it any other way at the moment. If anyone else wants to investigate the issue further, I'm happy to hear the results. Until then, for all other users, I recommend downgrading TypeScript to v4.9.5. |
Thank you for your reactivity! Yes, I'll try to downgrade and see if everything works smoothly :) At the same time, I'll investigate about that problem too. |
The way it was resolved in kysely: |
Thank you for the tip. I will try to investigate this in the next few weeks. |
I'm getting the same error message when using with As a workaround I'm using import {object} from "valibot"
import {FileOutput} from "./FileOutput.js"
import {ImageSize} from "./ImageSize.js"
export const ImageOutput = object({
...FileOutput.object,
metadata: ImageSize
}) |
Yes, that works too. Thank you! Another workaround that works in most cases is import { intersection, object, string } from 'valibot';
const Object1 = object({ key1: string() });
const Object2 = object({ key2: string() });
const Object3 = intersection([Object1, Object2]); |
I noticed marge slowdown in my TypeScript checking performance recently. I tracked it back to this and a switch from Running TypeScript v5.3.3 and Valibot v0.25.0. |
Here is a guide that help to choose between |
I am toying with the idea of removing import * as v from 'valibot';
const ObjectSchema1 = v.object({ key1: v.string() });
const ObjectSchema2 = v.object({ key2: v.number() });
const MergedSchema1 = v.merge([ObjectSchema1, ObjectSchema2]);
// This is the workaround that accomplishes exactly the same thing
const MergedSchema2 = v.object({
...ObjectSchema1.entries,
...ObjectSchema2.entries,
}); |
I think this is fixed in v0.30.0 |
Hello and first of all, thank you for your work with this library.
I was eager to migrate from
zod
tovalibot
after encountering this error on the use of schemas with manyunion
andtransform
but the same one seems to occur.Is there maybe a good practice to avoid it?
Thank you
The text was updated successfully, but these errors were encountered: