This commit is contained in:
@@ -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"]
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user