Form work
All checks were successful
Lint / lint (push) Successful in 19s

This commit is contained in:
Julien Valverdé
2025-04-19 01:13:41 +02:00
parent 86dde2d286
commit b78f99e808
2 changed files with 22 additions and 9 deletions

View File

@@ -35,12 +35,19 @@ export interface ArrayFormField<
readonly elements: readonly Formify.Formify<Value>[]
}
export interface StructFormField<
export type StructFormField<
S extends Schema.Struct<Fields>,
Fields extends Schema.Struct.Fields,
> extends FormField<S> {
readonly fields: { readonly [K in keyof Fields]: Formify.Formify<Fields[K]> }
> = (
& FormField<S>
& { readonly fields: { readonly [K in keyof Fields]: Formify.Formify<Fields[K]> } }
& {
[K in keyof Fields as Fields[K] extends
Schema.tag<infer _> ? K : never
]: Fields[K] extends
Schema.tag<infer Tag> ? Tag : never
}
)
export interface GenericFormField<S extends Schema.Schema.Any> extends FormField<S> {
readonly value: S["Type"]

View File

@@ -22,7 +22,7 @@ export type Formify<S> = (
)
const LoginForm = Schema.Union(
const Login = Schema.Union(
Schema.Struct({
_tag: Schema.tag("ByEmail"),
email: Schema.String,
@@ -34,12 +34,18 @@ const LoginForm = Schema.Union(
phone: Schema.String,
password: Schema.RedactedFromSelf(Schema.String),
}),
)
type LoginFormTree = Formify<typeof LoginForm>
declare const loginFormTree: LoginFormTree
switch (loginFormTree.member.fields._tag.value) {
Schema.TaggedStruct("ByKey", {
id: Schema.String,
password: Schema.RedactedFromSelf(Schema.String),
}),
)
type LoginForm = Formify<typeof Login>
declare const loginForm: LoginForm
switch (loginForm.member._tag) {
case "ByEmail":
loginForm.member
break
case "ByPhone":
break