Replies: 2 comments
-
|
@sleewoo Hi!
The following is the recommended fallback for the Base deprecation. import Value from 'typebox/value'
import Type from 'typebox'
// ------------------------------------------------------------------
//
// FileType:
//
// Unsafe - Used to create user-defined schema and inference.
// Refine - Used to create Check logic.
//
// ------------------------------------------------------------------
const FileType = () => Type.Refine(Type.Unsafe<File>({ /* schema */ }), value => {
return value instanceof File
}, "must be File")
// ------------------------------------------------------------------
// Example
// ------------------------------------------------------------------
const T = Type.Object({
file: FileType()
})
const A = Value.Parse(T, { file: new File([], 'index.ts') })
const B = Value.Parse(T, { file: null })
// Error: {
// source: "Parse",
// errors: [
// {
// keyword: "~refine",
// schemaPath: "#/properties/file",
// instancePath: "/file",
// params: { index: 0, message: "must be File" },
// message: "must be File"
// }
// ],
// value: { file: null }
// }The recommendation moving forward will be to use TUnsafe (as per 0.34.x) which allows for custom schema representations + inference, and the new TRefine type added in 1.x which implements custom Check logic for the type. These interfaces are a bit more inline with the TypeBox design, and where Base was primarily written in service of Standard Schema (which TypeBox no longer supports) If you have any questions on the above, feel free to ping. Happy to discuss. |
Beta Was this translation helpful? Give feedback.
-
|
Thanks @sinclairzx81 |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
namely, what would be a replacement for this?
Beta Was this translation helpful? Give feedback.
All reactions