-
Notifications
You must be signed in to change notification settings - Fork 935
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
types: Lazy class is not exported #1954
Comments
I have the exact same issue with the following code: import { lazy, AnySchema } from 'yup';
export const LazyEmptySchema = (schema: AnySchema, emptySchema: AnySchema) => {
return lazy((value) =>
value === undefined || value === '' ? emptySchema : schema
);
}; |
Same issue here! Without Lazy export, it breaks all my types. The below code is what I had pre v1 but lib was removed and Lazy is no longer exported.
|
i have same issue here: export const yupDynamicObject = (objectSchema: yup.AnyObjectSchema) => {
return yup.lazy((value) => {
if (!value || typeof value !== "object") {
return objectSchema;
}
return objectSchema.concat(
yup.object(Object.fromEntries(Object.keys(value).map((k) => [k, yup.mixed()])))
);
}); fixed from unknow type convert to AnyObjectSchema type, as: export const yupDynamicObject = (objectSchema: yup.AnyObjectSchema) => {
const lazySchema = yup.lazy((value) => {
if (!value || typeof value !== "object") {
return objectSchema;
}
return objectSchema.concat(
yup.object(Object.fromEntries(Object.keys(value).map((k) => [k, yup.mixed()])))
);
}) as unknown;
return lazySchema as yup.AnyObjectSchema;
}; |
Is it possible to solve the issue, instead of forcing us to typecast? |
Currently using |
PRs welcome if you want to move things along |
Describe the bug
The
Lazy
class is not exported, while the factory function to create an instance ofLazy
is.All the other factory functions are paired paired with exports of the classes (
NumberSchema
,StringSchema
,MixedSchema
, etc.) that they create.This is problematic when one uses
lazy()
to define a schema in one file, andexport
it for use in another (e.g. a React component).The following errors are produced:
To Reproduce
Define a schema using
lazy()
and export it.Expected behavior
I am able to define a schema using
lazy()
and not receive any of the above TypeScript errors.Platform (please complete the following information):
Additional context
Yup 1.0.2
The text was updated successfully, but these errors were encountered: