【发布时间】:2020-02-08 21:06:59
【问题描述】:
我想通过将架构放在单独的文件中来组织我的表单代码。我注意到,当我导出一个 yup 模式,然后将其导入另一个模式时,它总是会失败。模式数据似乎是正确的(当我控制台日志时),但是,导入模式的验证永远不会运行。
例子:
myAdditionalSchema.js
export const otherSchema = object({
someValue: string(),
})
myMainSchema.js
import { otherSchema } from "myAdditionalSchema"
export const constMainSchema = object({
myValue: string(),
}).concat(otherSchema)
如果我将所有这些模式都放在同一个文件中,我不会遇到此问题,只有在导入它们时才会遇到此问题。
例如,这是有效的:
export const constMainSchema = object({
myValue: string(),
}).concat(object({
someValue: string(),
}))
这也有效:
const otherSchema = object({
someValue: string(),
})
export const constMainSchema = object({
myValue: string(),
}).concat(otherSchema)
在导入它们时我需要做些什么不同的事情吗?对于上下文,我将它与 Formik 一起使用。
【问题讨论】: