diff --git a/packages/effect-fc/src/types/Form.ts b/packages/effect-fc/src/types/Form.ts index aa40de1..23b14a0 100644 --- a/packages/effect-fc/src/types/Form.ts +++ b/packages/effect-fc/src/types/Form.ts @@ -1,4 +1,5 @@ -import { Effectable, Schema, type Pipeable } from "effect" +import { Effectable, Option, Schema, Subscribable, SubscriptionRef, type ParseResult, type Pipeable } from "effect" +import type * as PropertyPath from "./PropertyPath.js" export const TypeId: unique symbol = Symbol.for("effect-fc/types/Form") @@ -7,9 +8,20 @@ export type TypeId = typeof TypeId export interface Form extends Pipeable.Pipeable { readonly schema: Schema.Schema + readonly valueRef: SubscriptionRef.SubscriptionRef + readonly errorSubscribable: Subscribable.Subscribable> + + useRef

>(path: P): SubscriptionRef.SubscriptionRef> + useIssues(path: PropertyPath.Paths): readonly ParseResult.ParseIssue[] } class FormImpl -extends Effectable.Class<> implements Form<> { +extends Effectable.Class<> implements Form { readonly [TypeId]: TypeId = TypeId } + + +const TestSchema = Schema.Struct({ + name: Schema.String +}) +declare const form: Form diff --git a/packages/effect-fc/src/types/PropertyPath.ts b/packages/effect-fc/src/types/PropertyPath.ts index 6b59d37..a779e1e 100644 --- a/packages/effect-fc/src/types/PropertyPath.ts +++ b/packages/effect-fc/src/types/PropertyPath.ts @@ -3,9 +3,9 @@ import { Array, Function, Option, Predicate } from "effect" type Prev = readonly [never, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] -export type Paths = [] | ( - D extends never ? [] : - T extends Seen ? [] : +export type Paths = readonly [] | ( + D extends never ? readonly [] : + T extends Seen ? readonly [] : T extends readonly any[] ? ArrayPaths : T extends object ? ObjectPaths : never @@ -13,8 +13,8 @@ export type Paths = [] | ( export type ArrayPaths = { [K in keyof T as K extends number ? K : never]: - | [K] - | [K, ...Paths] + | readonly [K] + | readonly [K, ...Paths] } extends infer O ? O[keyof O] : never @@ -22,13 +22,13 @@ export type ArrayPaths = { export type ObjectPaths = { [K in keyof T as K extends string | number | symbol ? K : never]-?: NonNullable extends infer V - ? [K] | [K, ...Paths] + ? readonly [K] | readonly [K, ...Paths] : never } extends infer O ? O[keyof O] : never -export type ValueFromPath = P extends [infer Head, ...infer Tail] +export type ValueFromPath = P extends [infer Head, ...infer Tail] ? Head extends keyof T ? ValueFromPath : T extends readonly any[]