Add signature definition
Lint / lint (push) Successful in 44s

This commit is contained in:
Julien Valverdé
2026-05-11 08:45:33 +02:00
parent e5d0808b02
commit c011ff99a4
3 changed files with 78 additions and 76 deletions
+8 -7
View File
@@ -37,8 +37,8 @@ export type AsyncProps = Omit<React.SuspenseProps, "children">
export const AsyncPrototype: AsyncPrototype = Object.freeze({ export const AsyncPrototype: AsyncPrototype = Object.freeze({
[AsyncTypeId]: AsyncTypeId, [AsyncTypeId]: AsyncTypeId,
asFunctionComponent<P extends {}, A extends React.ReactNode, E, R>( asFunctionComponent<P extends {}, A extends React.ReactNode, E, R, F extends Component.Component.Signature>(
this: Component.Component<P, A, E, R> & Async, this: Component.Component<P, A, E, R, F> & Async,
runtimeRef: React.RefObject<Runtime.Runtime<Exclude<R, Scope.Scope>>>, runtimeRef: React.RefObject<Runtime.Runtime<Exclude<R, Scope.Scope>>>,
) { ) {
const Inner = (props: { readonly promise: Promise<React.ReactNode> }) => React.use(props.promise) const Inner = (props: { readonly promise: Promise<React.ReactNode> }) => React.use(props.promise)
@@ -106,7 +106,7 @@ export const isAsync = (u: unknown): u is Async => Predicate.hasProperty(u, Asyn
* ) * )
* ``` * ```
*/ */
export const async = <T extends Component.Component<any, any, any, any>>( export const async = <T extends Component.Component.Any>(
self: T & ( self: T & (
"promise" extends keyof Component.Component.Props<T> "promise" extends keyof Component.Component.Props<T>
? "The 'promise' prop name is restricted for Async components. Please rename the 'promise' prop to something else." ? "The 'promise' prop name is restricted for Async components. Please rename the 'promise' prop to something else."
@@ -118,7 +118,8 @@ export const async = <T extends Component.Component<any, any, any, any>>(
Component.Component.Props<T> & AsyncProps, Component.Component.Props<T> & AsyncProps,
Component.Component.Success<T>, Component.Component.Success<T>,
Component.Component.Error<T>, Component.Component.Error<T>,
Component.Component.Context<T> Component.Component.Context<T>,
Component.Component.DefaultSignature<Component.Component.Props<T> & AsyncProps, Component.Component.Success<T>>
> >
& Async & Async
) => Object.setPrototypeOf( ) => Object.setPrototypeOf(
@@ -154,14 +155,14 @@ export const async = <T extends Component.Component<any, any, any, any>>(
* ``` * ```
*/ */
export const withOptions: { export const withOptions: {
<T extends Component.Component<any, any, any, any> & Async>( <T extends Component.Component.Any & Async>(
options: Partial<AsyncOptions> options: Partial<AsyncOptions>
): (self: T) => T ): (self: T) => T
<T extends Component.Component<any, any, any, any> & Async>( <T extends Component.Component.Any & Async>(
self: T, self: T,
options: Partial<AsyncOptions>, options: Partial<AsyncOptions>,
): T ): T
} = Function.dual(2, <T extends Component.Component<any, any, any, any> & Async>( } = Function.dual(2, <T extends Component.Component.Any & Async>(
self: T, self: T,
options: Partial<AsyncOptions>, options: Partial<AsyncOptions>,
): T => Object.setPrototypeOf( ): T => Object.setPrototypeOf(
+66 -65
View File
@@ -10,36 +10,44 @@ export type ComponentTypeId = typeof ComponentTypeId
/** /**
* Represents an Effect-based React Component that integrates the Effect system with React. * Represents an Effect-based React Component that integrates the Effect system with React.
*/ */
export interface Component<P extends {}, A extends React.ReactNode, E, R> export interface Component<P extends {}, A extends React.ReactNode, E, R, F extends Component.Signature>
extends ComponentPrototype<P, A, R>, ComponentOptions { extends ComponentPrototype<P, R, F>, ComponentOptions {
new(_: never): Record<string, never> new(_: never): Record<string, never>
readonly [ComponentTypeId]: ComponentTypeId readonly [ComponentTypeId]: ComponentTypeId
readonly "~Props": P readonly "~Props": P
readonly "~Success": A readonly "~Success": A
readonly "~Error": E readonly "~Error": E
readonly "~Context": R readonly "~Context": R
readonly "~Function": F
readonly body: (props: P) => Effect.Effect<A, E, R> readonly body: (props: P) => Effect.Effect<A, E, R>
} }
export declare namespace Component { export declare namespace Component {
export type Props<T extends Component<any, any, any, any>> = [T] extends [Component<infer P, infer _A, infer _E, infer _R>] ? P : never export type Default<P extends {}, A extends React.ReactNode, E, R> = Component<P, A, E, R, DefaultSignature<P, A>>
export type Success<T extends Component<any, any, any, any>> = [T] extends [Component<infer _P, infer A, infer _E, infer _R>] ? A : never export type Any = Component<any, any, any, any, any>
export type Error<T extends Component<any, any, any, any>> = [T] extends [Component<infer _P, infer _A, infer E, infer _R>] ? E : never
export type Context<T extends Component<any, any, any, any>> = [T] extends [Component<infer _P, infer _A, infer _E, infer R>] ? R : never
export type AsComponent<T extends Component<any, any, any, any>> = Component<Props<T>, Success<T>, Error<T>, Context<T>> export type Signature = (props: any) => React.ReactNode
export type DefaultSignature<P extends {}, A extends React.ReactNode> = (props: P) => A
export type Props<T extends Any> = [T] extends [Component<infer P, infer _A, infer _E, infer _R, infer _F>] ? P : never
export type Success<T extends Any> = [T] extends [Component<infer _P, infer A, infer _E, infer _R, infer _F>] ? A : never
export type Error<T extends Any> = [T] extends [Component<infer _P, infer _A, infer E, infer _R, infer _F>] ? E : never
export type Context<T extends Any> = [T] extends [Component<infer _P, infer _A, infer _E, infer R, infer _F>] ? R : never
export type Function<T extends Any> = [T] extends [Component<infer _P, infer _A, infer _E, infer _R, infer F>] ? F : never
export type AsComponent<T extends Any> = Component<Props<T>, Success<T>, Error<T>, Context<T>, Function<T>>
} }
export interface ComponentPrototype<P extends {}, A extends React.ReactNode, R> export interface ComponentPrototype<P extends {}, R, F extends Component.Signature>
extends Pipeable.Pipeable { extends Pipeable.Pipeable {
readonly [ComponentTypeId]: ComponentTypeId readonly [ComponentTypeId]: ComponentTypeId
readonly use: Effect.Effect<(props: P) => A, never, Exclude<R, Scope.Scope>> readonly use: Effect.Effect<F, never, Exclude<R, Scope.Scope>>
asFunctionComponent( asFunctionComponent(
runtimeRef: React.Ref<Runtime.Runtime<Exclude<R, Scope.Scope>>> runtimeRef: React.Ref<Runtime.Runtime<Exclude<R, Scope.Scope>>>
): (props: P) => A ): F
setFunctionComponentName(f: React.FC<P>): void setFunctionComponentName(f: React.FC<P>): void
transformFunctionComponent(f: React.FC<P>): React.FC<P> transformFunctionComponent(f: React.FC<P>): React.FC<P>
@@ -51,20 +59,20 @@ export const ComponentPrototype: ComponentPrototype<any, any, any> = Object.free
get use() { return use(this) }, get use() { return use(this) },
asFunctionComponent<P extends {}, A extends React.ReactNode, E, R>( asFunctionComponent<P extends {}, A extends React.ReactNode, E, R, F extends Component.Signature>(
this: Component<P, A, E, R>, this: Component<P, A, E, R, F>,
runtimeRef: React.RefObject<Runtime.Runtime<Exclude<R, Scope.Scope>>>, runtimeRef: React.RefObject<Runtime.Runtime<Exclude<R, Scope.Scope>>>,
) { ) {
return (props: P) => Runtime.runSync(runtimeRef.current)( return ((props: P) => Runtime.runSync(runtimeRef.current)(
Effect.andThen( Effect.andThen(
useScope([], this), useScope([], this),
scope => Effect.provideService(this.body(props), Scope.Scope, scope), scope => Effect.provideService(this.body(props), Scope.Scope, scope),
) )
) ))
}, },
setFunctionComponentName<P extends {}, A extends React.ReactNode, E, R>( setFunctionComponentName<P extends {}, A extends React.ReactNode, E, R, F extends Component.Signature>(
this: Component<P, A, E, R>, this: Component<P, A, E, R, F>,
f: React.FC<P>, f: React.FC<P>,
) { ) {
f.displayName = this.displayName ?? "Anonymous" f.displayName = this.displayName ?? "Anonymous"
@@ -73,8 +81,8 @@ export const ComponentPrototype: ComponentPrototype<any, any, any> = Object.free
transformFunctionComponent: identity, transformFunctionComponent: identity,
} as const) } as const)
const use = Effect.fnUntraced(function* <P extends {}, A extends React.ReactNode, E, R>( const use = Effect.fnUntraced(function* <P extends {}, A extends React.ReactNode, E, R, F extends Component.Signature>(
self: Component<P, A, E, R> self: Component<P, A, E, R, F>
) { ) {
// biome-ignore lint/style/noNonNullAssertion: React ref initialization // biome-ignore lint/style/noNonNullAssertion: React ref initialization
const runtimeRef = React.useRef<Runtime.Runtime<Exclude<R, Scope.Scope>>>(null!) const runtimeRef = React.useRef<Runtime.Runtime<Exclude<R, Scope.Scope>>>(null!)
@@ -82,7 +90,7 @@ const use = Effect.fnUntraced(function* <P extends {}, A extends React.ReactNode
return yield* React.useState(() => Runtime.runSync(runtimeRef.current)(Effect.cachedFunction( return yield* React.useState(() => Runtime.runSync(runtimeRef.current)(Effect.cachedFunction(
(_services: readonly any[]) => Effect.sync(() => { (_services: readonly any[]) => Effect.sync(() => {
const f: React.FC<P> = self.asFunctionComponent(runtimeRef) const f = self.asFunctionComponent(runtimeRef)
self.setFunctionComponentName(f) self.setFunctionComponentName(f)
return self.transformFunctionComponent(f) return self.transformFunctionComponent(f)
}), }),
@@ -131,13 +139,13 @@ export const defaultOptions: ComponentOptions = {
} }
export const isComponent = (u: unknown): u is Component<{}, React.ReactNode, unknown, unknown> => Predicate.hasProperty(u, ComponentTypeId) export const isComponent = (u: unknown): u is Component.Default<{}, React.ReactNode, unknown, unknown> => Predicate.hasProperty(u, ComponentTypeId)
export declare namespace make { export declare namespace make {
export type Gen = { export type Gen = {
<Eff extends Utils.YieldWrap<Effect.Effect<any, any, any>>, A extends React.ReactNode, P extends {} = {}>( <Eff extends Utils.YieldWrap<Effect.Effect<any, any, any>>, A extends React.ReactNode, P extends {} = {}>(
body: (props: P) => Generator<Eff, A, never> body: (props: P) => Generator<Eff, A, never>
): Component< ): Component.Default<
P, A, P, A,
[Eff] extends [never] ? never : [Eff] extends [Utils.YieldWrap<Effect.Effect<infer _A, infer E, infer _R>>] ? E : never, [Eff] extends [never] ? never : [Eff] extends [Utils.YieldWrap<Effect.Effect<infer _A, infer E, infer _R>>] ? E : never,
[Eff] extends [never] ? never : [Eff] extends [Utils.YieldWrap<Effect.Effect<infer _A, infer _E, infer R>>] ? R : never [Eff] extends [never] ? never : [Eff] extends [Utils.YieldWrap<Effect.Effect<infer _A, infer _E, infer R>>] ? R : never
@@ -152,7 +160,7 @@ export declare namespace make {
>, >,
props: NoInfer<P>, props: NoInfer<P>,
) => B, ) => B,
): Component<P, Effect.Effect.Success<Effect.Effect.AsEffect<B>>, Effect.Effect.Error<B>, Effect.Effect.Context<B>> ): Component.Default<P, Effect.Effect.Success<Effect.Effect.AsEffect<B>>, Effect.Effect.Error<B>, Effect.Effect.Context<B>>
<Eff extends Utils.YieldWrap<Effect.Effect<any, any, any>>, A, B, C extends Effect.Effect<React.ReactNode, any, any>, P extends {} = {}>( <Eff extends Utils.YieldWrap<Effect.Effect<any, any, any>>, A, B, C extends Effect.Effect<React.ReactNode, any, any>, P extends {} = {}>(
body: (props: P) => Generator<Eff, A, never>, body: (props: P) => Generator<Eff, A, never>,
a: ( a: (
@@ -164,7 +172,7 @@ export declare namespace make {
props: NoInfer<P>, props: NoInfer<P>,
) => B, ) => B,
b: (_: B, props: NoInfer<P>) => C, b: (_: B, props: NoInfer<P>) => C,
): Component<P, Effect.Effect.Success<Effect.Effect.AsEffect<C>>, Effect.Effect.Error<C>, Effect.Effect.Context<C>> ): Component.Default<P, Effect.Effect.Success<Effect.Effect.AsEffect<C>>, Effect.Effect.Error<C>, Effect.Effect.Context<C>>
<Eff extends Utils.YieldWrap<Effect.Effect<any, any, any>>, A, B, C, D extends Effect.Effect<React.ReactNode, any, any>, P extends {} = {}>( <Eff extends Utils.YieldWrap<Effect.Effect<any, any, any>>, A, B, C, D extends Effect.Effect<React.ReactNode, any, any>, P extends {} = {}>(
body: (props: P) => Generator<Eff, A, never>, body: (props: P) => Generator<Eff, A, never>,
a: ( a: (
@@ -177,7 +185,7 @@ export declare namespace make {
) => B, ) => B,
b: (_: B, props: NoInfer<P>) => C, b: (_: B, props: NoInfer<P>) => C,
c: (_: C, props: NoInfer<P>) => D, c: (_: C, props: NoInfer<P>) => D,
): Component<P, Effect.Effect.Success<Effect.Effect.AsEffect<D>>, Effect.Effect.Error<D>, Effect.Effect.Context<D>> ): Component.Default<P, Effect.Effect.Success<Effect.Effect.AsEffect<D>>, Effect.Effect.Error<D>, Effect.Effect.Context<D>>
<Eff extends Utils.YieldWrap<Effect.Effect<any, any, any>>, A, B, C, D, E extends Effect.Effect<React.ReactNode, any, any>, P extends {} = {}>( <Eff extends Utils.YieldWrap<Effect.Effect<any, any, any>>, A, B, C, D, E extends Effect.Effect<React.ReactNode, any, any>, P extends {} = {}>(
body: (props: P) => Generator<Eff, A, never>, body: (props: P) => Generator<Eff, A, never>,
a: ( a: (
@@ -191,7 +199,7 @@ export declare namespace make {
b: (_: B, props: NoInfer<P>) => C, b: (_: B, props: NoInfer<P>) => C,
c: (_: C, props: NoInfer<P>) => D, c: (_: C, props: NoInfer<P>) => D,
d: (_: D, props: NoInfer<P>) => E, d: (_: D, props: NoInfer<P>) => E,
): Component<P, Effect.Effect.Success<Effect.Effect.AsEffect<E>>, Effect.Effect.Error<E>, Effect.Effect.Context<E>> ): Component.Default<P, Effect.Effect.Success<Effect.Effect.AsEffect<E>>, Effect.Effect.Error<E>, Effect.Effect.Context<E>>
<Eff extends Utils.YieldWrap<Effect.Effect<any, any, any>>, A, B, C, D, E, F extends Effect.Effect<React.ReactNode, any, any>, P extends {} = {}>( <Eff extends Utils.YieldWrap<Effect.Effect<any, any, any>>, A, B, C, D, E, F extends Effect.Effect<React.ReactNode, any, any>, P extends {} = {}>(
body: (props: P) => Generator<Eff, A, never>, body: (props: P) => Generator<Eff, A, never>,
a: ( a: (
@@ -206,7 +214,7 @@ export declare namespace make {
c: (_: C, props: NoInfer<P>) => D, c: (_: C, props: NoInfer<P>) => D,
d: (_: D, props: NoInfer<P>) => E, d: (_: D, props: NoInfer<P>) => E,
e: (_: E, props: NoInfer<P>) => F, e: (_: E, props: NoInfer<P>) => F,
): Component<P, Effect.Effect.Success<Effect.Effect.AsEffect<F>>, Effect.Effect.Error<F>, Effect.Effect.Context<F>> ): Component.Default<P, Effect.Effect.Success<Effect.Effect.AsEffect<F>>, Effect.Effect.Error<F>, Effect.Effect.Context<F>>
<Eff extends Utils.YieldWrap<Effect.Effect<any, any, any>>, A, B, C, D, E, F, G extends Effect.Effect<React.ReactNode, any, any>, P extends {} = {}>( <Eff extends Utils.YieldWrap<Effect.Effect<any, any, any>>, A, B, C, D, E, F, G extends Effect.Effect<React.ReactNode, any, any>, P extends {} = {}>(
body: (props: P) => Generator<Eff, A, never>, body: (props: P) => Generator<Eff, A, never>,
a: ( a: (
@@ -222,7 +230,7 @@ export declare namespace make {
d: (_: D, props: NoInfer<P>) => E, d: (_: D, props: NoInfer<P>) => E,
e: (_: E, props: NoInfer<P>) => F, e: (_: E, props: NoInfer<P>) => F,
f: (_: F, props: NoInfer<P>) => G, f: (_: F, props: NoInfer<P>) => G,
): Component<P, Effect.Effect.Success<Effect.Effect.AsEffect<G>>, Effect.Effect.Error<G>, Effect.Effect.Context<G>> ): Component.Default<P, Effect.Effect.Success<Effect.Effect.AsEffect<G>>, Effect.Effect.Error<G>, Effect.Effect.Context<G>>
<Eff extends Utils.YieldWrap<Effect.Effect<any, any, any>>, A, B, C, D, E, F, G, H extends Effect.Effect<React.ReactNode, any, any>, P extends {} = {}>( <Eff extends Utils.YieldWrap<Effect.Effect<any, any, any>>, A, B, C, D, E, F, G, H extends Effect.Effect<React.ReactNode, any, any>, P extends {} = {}>(
body: (props: P) => Generator<Eff, A, never>, body: (props: P) => Generator<Eff, A, never>,
a: ( a: (
@@ -239,7 +247,7 @@ export declare namespace make {
e: (_: E, props: NoInfer<P>) => F, e: (_: E, props: NoInfer<P>) => F,
f: (_: F, props: NoInfer<P>) => G, f: (_: F, props: NoInfer<P>) => G,
g: (_: G, props: NoInfer<P>) => H, g: (_: G, props: NoInfer<P>) => H,
): Component<P, Effect.Effect.Success<Effect.Effect.AsEffect<H>>, Effect.Effect.Error<H>, Effect.Effect.Context<H>> ): Component.Default<P, Effect.Effect.Success<Effect.Effect.AsEffect<H>>, Effect.Effect.Error<H>, Effect.Effect.Context<H>>
<Eff extends Utils.YieldWrap<Effect.Effect<any, any, any>>, A, B, C, D, E, F, G, H, I extends Effect.Effect<React.ReactNode, any, any>, P extends {} = {}>( <Eff extends Utils.YieldWrap<Effect.Effect<any, any, any>>, A, B, C, D, E, F, G, H, I extends Effect.Effect<React.ReactNode, any, any>, P extends {} = {}>(
body: (props: P) => Generator<Eff, A, never>, body: (props: P) => Generator<Eff, A, never>,
a: ( a: (
@@ -257,7 +265,7 @@ export declare namespace make {
f: (_: F, props: NoInfer<P>) => G, f: (_: F, props: NoInfer<P>) => G,
g: (_: G, props: NoInfer<P>) => H, g: (_: G, props: NoInfer<P>) => H,
h: (_: H, props: NoInfer<P>) => I, h: (_: H, props: NoInfer<P>) => I,
): Component<P, Effect.Effect.Success<Effect.Effect.AsEffect<I>>, Effect.Effect.Error<I>, Effect.Effect.Context<I>> ): Component.Default<P, Effect.Effect.Success<Effect.Effect.AsEffect<I>>, Effect.Effect.Error<I>, Effect.Effect.Context<I>>
<Eff extends Utils.YieldWrap<Effect.Effect<any, any, any>>, A, B, C, D, E, F, G, H, I, J extends Effect.Effect<React.ReactNode, any, any>, P extends {} = {}>( <Eff extends Utils.YieldWrap<Effect.Effect<any, any, any>>, A, B, C, D, E, F, G, H, I, J extends Effect.Effect<React.ReactNode, any, any>, P extends {} = {}>(
body: (props: P) => Generator<Eff, A, never>, body: (props: P) => Generator<Eff, A, never>,
a: ( a: (
@@ -276,35 +284,35 @@ export declare namespace make {
g: (_: G, props: NoInfer<P>) => H, g: (_: G, props: NoInfer<P>) => H,
h: (_: H, props: NoInfer<P>) => I, h: (_: H, props: NoInfer<P>) => I,
i: (_: I, props: NoInfer<P>) => J, i: (_: I, props: NoInfer<P>) => J,
): Component<P, Effect.Effect.Success<Effect.Effect.AsEffect<J>>, Effect.Effect.Error<J>, Effect.Effect.Context<J>> ): Component.Default<P, Effect.Effect.Success<Effect.Effect.AsEffect<J>>, Effect.Effect.Error<J>, Effect.Effect.Context<J>>
} }
export type NonGen = { export type NonGen = {
<Eff extends Effect.Effect<React.ReactNode, any, any>, P extends {} = {}>( <Eff extends Effect.Effect<React.ReactNode, any, any>, P extends {} = {}>(
body: (props: P) => Eff body: (props: P) => Eff
): Component<P, Effect.Effect.Success<Effect.Effect.AsEffect<Eff>>, Effect.Effect.Error<Eff>, Effect.Effect.Context<Eff>> ): Component.Default<P, Effect.Effect.Success<Effect.Effect.AsEffect<Eff>>, Effect.Effect.Error<Eff>, Effect.Effect.Context<Eff>>
<Eff extends Effect.Effect<React.ReactNode, any, any>, A, P extends {} = {}>( <Eff extends Effect.Effect<React.ReactNode, any, any>, A, P extends {} = {}>(
body: (props: P) => A, body: (props: P) => A,
a: (_: A, props: NoInfer<P>) => Eff, a: (_: A, props: NoInfer<P>) => Eff,
): Component<P, Effect.Effect.Success<Effect.Effect.AsEffect<Eff>>, Effect.Effect.Error<Eff>, Effect.Effect.Context<Eff>> ): Component.Default<P, Effect.Effect.Success<Effect.Effect.AsEffect<Eff>>, Effect.Effect.Error<Eff>, Effect.Effect.Context<Eff>>
<Eff extends Effect.Effect<React.ReactNode, any, any>, A, B, P extends {} = {}>( <Eff extends Effect.Effect<React.ReactNode, any, any>, A, B, P extends {} = {}>(
body: (props: P) => A, body: (props: P) => A,
a: (_: A, props: NoInfer<P>) => B, a: (_: A, props: NoInfer<P>) => B,
b: (_: B, props: NoInfer<P>) => Eff, b: (_: B, props: NoInfer<P>) => Eff,
): Component<P, Effect.Effect.Success<Effect.Effect.AsEffect<Eff>>, Effect.Effect.Error<Eff>, Effect.Effect.Context<Eff>> ): Component.Default<P, Effect.Effect.Success<Effect.Effect.AsEffect<Eff>>, Effect.Effect.Error<Eff>, Effect.Effect.Context<Eff>>
<Eff extends Effect.Effect<React.ReactNode, any, any>, A, B, C, P extends {} = {}>( <Eff extends Effect.Effect<React.ReactNode, any, any>, A, B, C, P extends {} = {}>(
body: (props: P) => A, body: (props: P) => A,
a: (_: A, props: NoInfer<P>) => B, a: (_: A, props: NoInfer<P>) => B,
b: (_: B, props: NoInfer<P>) => C, b: (_: B, props: NoInfer<P>) => C,
c: (_: C, props: NoInfer<P>) => Eff, c: (_: C, props: NoInfer<P>) => Eff,
): Component<P, Effect.Effect.Success<Effect.Effect.AsEffect<Eff>>, Effect.Effect.Error<Eff>, Effect.Effect.Context<Eff>> ): Component.Default<P, Effect.Effect.Success<Effect.Effect.AsEffect<Eff>>, Effect.Effect.Error<Eff>, Effect.Effect.Context<Eff>>
<Eff extends Effect.Effect<React.ReactNode, any, any>, A, B, C, D, P extends {} = {}>( <Eff extends Effect.Effect<React.ReactNode, any, any>, A, B, C, D, P extends {} = {}>(
body: (props: P) => A, body: (props: P) => A,
a: (_: A, props: NoInfer<P>) => B, a: (_: A, props: NoInfer<P>) => B,
b: (_: B, props: NoInfer<P>) => C, b: (_: B, props: NoInfer<P>) => C,
c: (_: C, props: NoInfer<P>) => D, c: (_: C, props: NoInfer<P>) => D,
d: (_: D, props: NoInfer<P>) => Eff, d: (_: D, props: NoInfer<P>) => Eff,
): Component<P, Effect.Effect.Success<Effect.Effect.AsEffect<Eff>>, Effect.Effect.Error<Eff>, Effect.Effect.Context<Eff>> ): Component.Default<P, Effect.Effect.Success<Effect.Effect.AsEffect<Eff>>, Effect.Effect.Error<Eff>, Effect.Effect.Context<Eff>>
<Eff extends Effect.Effect<React.ReactNode, any, any>, A, B, C, D, E, P extends {} = {}>( <Eff extends Effect.Effect<React.ReactNode, any, any>, A, B, C, D, E, P extends {} = {}>(
body: (props: P) => A, body: (props: P) => A,
a: (_: A, props: NoInfer<P>) => B, a: (_: A, props: NoInfer<P>) => B,
@@ -312,7 +320,7 @@ export declare namespace make {
c: (_: C, props: NoInfer<P>) => D, c: (_: C, props: NoInfer<P>) => D,
d: (_: D, props: NoInfer<P>) => E, d: (_: D, props: NoInfer<P>) => E,
e: (_: E, props: NoInfer<P>) => Eff, e: (_: E, props: NoInfer<P>) => Eff,
): Component<P, Effect.Effect.Success<Effect.Effect.AsEffect<Eff>>, Effect.Effect.Error<Eff>, Effect.Effect.Context<Eff>> ): Component.Default<P, Effect.Effect.Success<Effect.Effect.AsEffect<Eff>>, Effect.Effect.Error<Eff>, Effect.Effect.Context<Eff>>
<Eff extends Effect.Effect<React.ReactNode, any, any>, A, B, C, D, E, F, P extends {} = {}>( <Eff extends Effect.Effect<React.ReactNode, any, any>, A, B, C, D, E, F, P extends {} = {}>(
body: (props: P) => A, body: (props: P) => A,
a: (_: A, props: NoInfer<P>) => B, a: (_: A, props: NoInfer<P>) => B,
@@ -321,7 +329,7 @@ export declare namespace make {
d: (_: D, props: NoInfer<P>) => E, d: (_: D, props: NoInfer<P>) => E,
e: (_: E, props: NoInfer<P>) => F, e: (_: E, props: NoInfer<P>) => F,
f: (_: F, props: NoInfer<P>) => Eff, f: (_: F, props: NoInfer<P>) => Eff,
): Component<P, Effect.Effect.Success<Effect.Effect.AsEffect<Eff>>, Effect.Effect.Error<Eff>, Effect.Effect.Context<Eff>> ): Component.Default<P, Effect.Effect.Success<Effect.Effect.AsEffect<Eff>>, Effect.Effect.Error<Eff>, Effect.Effect.Context<Eff>>
<Eff extends Effect.Effect<React.ReactNode, any, any>, A, B, C, D, E, F, G, P extends {} = {}>( <Eff extends Effect.Effect<React.ReactNode, any, any>, A, B, C, D, E, F, G, P extends {} = {}>(
body: (props: P) => A, body: (props: P) => A,
a: (_: A, props: NoInfer<P>) => B, a: (_: A, props: NoInfer<P>) => B,
@@ -331,7 +339,7 @@ export declare namespace make {
e: (_: E, props: NoInfer<P>) => F, e: (_: E, props: NoInfer<P>) => F,
f: (_: F, props: NoInfer<P>) => G, f: (_: F, props: NoInfer<P>) => G,
g: (_: G, props: NoInfer<P>) => Eff, g: (_: G, props: NoInfer<P>) => Eff,
): Component<P, Effect.Effect.Success<Effect.Effect.AsEffect<Eff>>, Effect.Effect.Error<Eff>, Effect.Effect.Context<Eff>> ): Component.Default<P, Effect.Effect.Success<Effect.Effect.AsEffect<Eff>>, Effect.Effect.Error<Eff>, Effect.Effect.Context<Eff>>
<Eff extends Effect.Effect<React.ReactNode, any, any>, A, B, C, D, E, F, G, H, P extends {} = {}>( <Eff extends Effect.Effect<React.ReactNode, any, any>, A, B, C, D, E, F, G, H, P extends {} = {}>(
body: (props: P) => A, body: (props: P) => A,
a: (_: A, props: NoInfer<P>) => B, a: (_: A, props: NoInfer<P>) => B,
@@ -342,7 +350,7 @@ export declare namespace make {
f: (_: F, props: NoInfer<P>) => G, f: (_: F, props: NoInfer<P>) => G,
g: (_: G, props: NoInfer<P>) => H, g: (_: G, props: NoInfer<P>) => H,
h: (_: H, props: NoInfer<P>) => Eff, h: (_: H, props: NoInfer<P>) => Eff,
): Component<P, Effect.Effect.Success<Effect.Effect.AsEffect<Eff>>, Effect.Effect.Error<Eff>, Effect.Effect.Context<Eff>> ): Component.Default<P, Effect.Effect.Success<Effect.Effect.AsEffect<Eff>>, Effect.Effect.Error<Eff>, Effect.Effect.Context<Eff>>
<Eff extends Effect.Effect<React.ReactNode, any, any>, A, B, C, D, E, F, G, H, I, P extends {} = {}>( <Eff extends Effect.Effect<React.ReactNode, any, any>, A, B, C, D, E, F, G, H, I, P extends {} = {}>(
body: (props: P) => A, body: (props: P) => A,
a: (_: A, props: NoInfer<P>) => B, a: (_: A, props: NoInfer<P>) => B,
@@ -354,7 +362,7 @@ export declare namespace make {
g: (_: G, props: NoInfer<P>) => H, g: (_: G, props: NoInfer<P>) => H,
h: (_: H, props: NoInfer<P>) => I, h: (_: H, props: NoInfer<P>) => I,
i: (_: I, props: NoInfer<P>) => Eff, i: (_: I, props: NoInfer<P>) => Eff,
): Component<P, Effect.Effect.Success<Effect.Effect.AsEffect<Eff>>, Effect.Effect.Error<Eff>, Effect.Effect.Context<Eff>> ): Component.Default<P, Effect.Effect.Success<Effect.Effect.AsEffect<Eff>>, Effect.Effect.Error<Eff>, Effect.Effect.Context<Eff>>
} }
} }
@@ -501,27 +509,20 @@ export const makeUntraced: (
) )
export declare namespace withSignature { export declare namespace withSignature {
export type Signature = (props: any) => React.ReactNode export type Result<T extends Component.Any, F extends Component.Signature> = (
& Omit<T, keyof Component.AsComponent<T>>
export type Result< & Component<Component.Props<T>, Component.Success<T>, Component.Error<T>, Component.Context<T>, F>
T extends Component<any, any, any, any>, )
F extends Signature,
> = Omit<T, "use" | "asFunctionComponent"> & {
readonly use: Effect.Effect<F, never, Exclude<Component.Context<T>, Scope.Scope>>
asFunctionComponent(
runtimeRef: React.Ref<Runtime.Runtime<Exclude<Component.Context<T>, Scope.Scope>>>
): F
}
} }
export const withSignature: { export const withSignature: {
<F extends withSignature.Signature>(): <T extends Component<any, any, any, any>>( <F extends Component.Signature>(): <T extends Component.Any>(
self: T self: T
) => withSignature.Result<T, F> ) => withSignature.Result<T, F>
<F extends withSignature.Signature, T extends Component<any, any, any, any>>( <F extends Component.Signature, T extends Component.Any>(
self: T self: T
): withSignature.Result<T, F> ): withSignature.Result<T, F>
} = (self?: Component<any, any, any, any>): any => self === undefined } = (self?: Component.Any): any => self === undefined
? identity ? identity
: self : self
@@ -542,14 +543,14 @@ export const withSignature: {
* ``` * ```
*/ */
export const withOptions: { export const withOptions: {
<T extends Component<any, any, any, any>>( <T extends Component.Any>(
options: Partial<ComponentOptions> options: Partial<ComponentOptions>
): (self: T) => T ): (self: T) => T
<T extends Component<any, any, any, any>>( <T extends Component.Any>(
self: T, self: T,
options: Partial<ComponentOptions>, options: Partial<ComponentOptions>,
): T ): T
} = Function.dual(2, <T extends Component<any, any, any, any>>( } = Function.dual(2, <T extends Component.Any>(
self: T, self: T,
options: Partial<ComponentOptions>, options: Partial<ComponentOptions>,
): T => Object.setPrototypeOf( ): T => Object.setPrototypeOf(
@@ -595,19 +596,19 @@ export const withOptions: {
* *
*/ */
export const withRuntime: { export const withRuntime: {
<P extends {}, A extends React.ReactNode, E, R>( <P extends {}, A extends React.ReactNode, E, R, F extends Component.Signature>(
context: React.Context<Runtime.Runtime<R>>, context: React.Context<Runtime.Runtime<R>>,
): (self: Component<P, A, E, Scope.Scope | NoInfer<R>>) => (props: P) => A ): (self: Component<P, A, E, Scope.Scope | NoInfer<R>, F>) => F
<P extends {}, A extends React.ReactNode, E, R>( <P extends {}, A extends React.ReactNode, E, R, F extends Component.Signature>(
self: Component<P, A, E, Scope.Scope | NoInfer<R>>, self: Component<P, A, E, Scope.Scope | NoInfer<R>, F>,
context: React.Context<Runtime.Runtime<R>>, context: React.Context<Runtime.Runtime<R>>,
): (props: P) => A ): F
} = Function.dual(2, <P extends {}, A extends React.ReactNode, E, R>( } = Function.dual(2, <P extends {}, A extends React.ReactNode, E, R, F extends Component.Signature>(
self: Component<P, A, E, R>, self: Component<P, A, E, R, F>,
context: React.Context<Runtime.Runtime<R>>, context: React.Context<Runtime.Runtime<R>>,
) => function WithRuntime(props: P) { ) => function WithRuntime(props: P) {
return React.createElement( return React.createElement(
Runtime.runSync(React.useContext(context))(self.use), Runtime.runSync(React.useContext(context))(self.use) as React.FC<P>,
props, props,
) )
}) })
+4 -4
View File
@@ -61,7 +61,7 @@ export const isMemoized = (u: unknown): u is Memoized<unknown> => Predicate.hasP
* ) * )
* ``` * ```
*/ */
export const memoized = <T extends Component.Component<any, any, any, any>>( export const memoized = <T extends Component.Component.Any>(
self: T self: T
): T & Memoized<Component.Component.Props<T>> => Object.setPrototypeOf( ): T & Memoized<Component.Component.Props<T>> => Object.setPrototypeOf(
Object.assign(function() {}, self), Object.assign(function() {}, self),
@@ -96,14 +96,14 @@ export const memoized = <T extends Component.Component<any, any, any, any>>(
* ``` * ```
*/ */
export const withOptions: { export const withOptions: {
<T extends Component.Component<any, any, any, any> & Memoized<any>>( <T extends Component.Component.Any & Memoized<any>>(
options: Partial<MemoizedOptions<Component.Component.Props<T>>> options: Partial<MemoizedOptions<Component.Component.Props<T>>>
): (self: T) => T ): (self: T) => T
<T extends Component.Component<any, any, any, any> & Memoized<any>>( <T extends Component.Component.Any & Memoized<any>>(
self: T, self: T,
options: Partial<MemoizedOptions<Component.Component.Props<T>>>, options: Partial<MemoizedOptions<Component.Component.Props<T>>>,
): T ): T
} = Function.dual(2, <T extends Component.Component<any, any, any, any> & Memoized<any>>( } = Function.dual(2, <T extends Component.Component.Any & Memoized<any>>(
self: T, self: T,
options: Partial<MemoizedOptions<Component.Component.Props<T>>>, options: Partial<MemoizedOptions<Component.Component.Props<T>>>,
): T => Object.setPrototypeOf( ): T => Object.setPrototypeOf(