This commit is contained in:
@@ -35,12 +35,19 @@ export interface ArrayFormField<
|
|||||||
readonly elements: readonly Formify.Formify<Value>[]
|
readonly elements: readonly Formify.Formify<Value>[]
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface StructFormField<
|
export type StructFormField<
|
||||||
S extends Schema.Struct<Fields>,
|
S extends Schema.Struct<Fields>,
|
||||||
Fields 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> {
|
export interface GenericFormField<S extends Schema.Schema.Any> extends FormField<S> {
|
||||||
readonly value: S["Type"]
|
readonly value: S["Type"]
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ export type Formify<S> = (
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
const LoginForm = Schema.Union(
|
const Login = Schema.Union(
|
||||||
Schema.Struct({
|
Schema.Struct({
|
||||||
_tag: Schema.tag("ByEmail"),
|
_tag: Schema.tag("ByEmail"),
|
||||||
email: Schema.String,
|
email: Schema.String,
|
||||||
@@ -34,12 +34,18 @@ const LoginForm = Schema.Union(
|
|||||||
phone: Schema.String,
|
phone: Schema.String,
|
||||||
password: Schema.RedactedFromSelf(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":
|
case "ByEmail":
|
||||||
|
loginForm.member
|
||||||
break
|
break
|
||||||
case "ByPhone":
|
case "ByPhone":
|
||||||
break
|
break
|
||||||
|
|||||||
Reference in New Issue
Block a user