import * as s from '@remix-run/data-schema' import * as fd from '@remix-run/data-schema/experimental/form' import { getSchemaMetadata } from '@remix-run/data-schema/experimental' import { max, maxLength, min, minLength } from '@remix-run/data-schema/checks' import type { FieldBinding, FieldBindings, GetConstraintsOptions } from './form.ts' type Equal = (() => value extends left ? 1 : 2) extends () => value extends right ? 1 : 2 ? true : false function expectType(_value?: condition): void {} expectType>() expectType< Equal< | 'datetime-local' | 'radio' | 'range' | 'file' | 'select' | 'textarea' extends GetConstraintsOptions['type'] ? true : false, true > >() const User = s.object({ id: s.string(), name: s.string().pipe(minLength(2), maxLength(50)), age: s.number().pipe(min(13), max(120)), }) expectType>() expectType>() const Profile = fd.object({ name: fd.text(getSchemaMetadata(User).shape.name), age: fd.number(getSchemaMetadata(User).shape.age), bio: fd.text(s.optional(s.string())), password: fd.password(s.string()), terms: fd.checkbox(s.literal(true)), }) expectType< Equal< fd.FormValue, { readonly name: string readonly age: number readonly bio: string | undefined readonly password: string readonly terms: true } > >() expectType['password'], FieldBinding<'password'>>>() const mutableEntries = { name: fd.text(s.string()) } const MutableForm = fd.object(mutableEntries) expectType>>() const RepeatedForm = fd.object({ tags: fd.fields(s.array(s.string())) }) expectType['tags'], FieldBinding<'fields'>>>() expectType, 'unknown'>, never>>() const UploadForm = fd.object({ avatar: fd.file(s.optional(s.instanceof_(Blob))), attachments: fd.files(s.array(s.instanceof_(Blob))), }) expectType['avatar'], FieldBinding<'file'>>>() expectType['attachments'], FieldBinding<'files'>>>()