From 53bceb3a8a6990222465c48a132d80439738f475 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Valverd=C3=A9?= Date: Thu, 7 Aug 2025 04:21:43 +0200 Subject: [PATCH] Traits fix --- packages/effect-fc/src/Memoized.ts | 2 +- packages/effect-fc/src/Suspense.ts | 31 ++++++++++++++++++------------ 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/packages/effect-fc/src/Memoized.ts b/packages/effect-fc/src/Memoized.ts index f12ccbf..10d17e5 100644 --- a/packages/effect-fc/src/Memoized.ts +++ b/packages/effect-fc/src/Memoized.ts @@ -27,7 +27,7 @@ export const memo = >( self: T ): T & Memoized>> => Object.setPrototypeOf( Object.assign(function() {}, self), - Object.seal({ ...Object.getPrototypeOf(self), ...MemoizedProto }), + Object.freeze({ ...Object.getPrototypeOf(self), ...MemoizedProto }), ) export const withOptions: { diff --git a/packages/effect-fc/src/Suspense.ts b/packages/effect-fc/src/Suspense.ts index a8bbe58..45212cf 100644 --- a/packages/effect-fc/src/Suspense.ts +++ b/packages/effect-fc/src/Suspense.ts @@ -1,7 +1,6 @@ import { Effect, Function, Predicate, Runtime, Scope } from "effect" import * as React from "react" import type * as Component from "./Component.js" -import type { ExcludeKeys } from "./utils.js" export const TypeId: unique symbol = Symbol.for("effect-fc/Suspense") @@ -22,16 +21,17 @@ export namespace Suspense { const SuspenseProto = Object.freeze({ [TypeId]: TypeId, - makeFunctionComponent( - this: Component.Component & Suspense, - runtimeRef: React.RefObject>, + + makeFunctionComponent( + this: Component.Component & Suspense, + runtimeRef: React.RefObject>>, scope: Scope.Scope, - ): React.FC { + ) { const SuspenseInner = (props: { readonly promise: Promise }) => React.use(props.promise) return ({ fallback, name, ...props }: Suspense.Props) => { const promise = Runtime.runPromise(runtimeRef.current)( - Effect.provideService(this.body(props), Scope.Scope, scope) + Effect.provideService(this.body(props as Component.FunctionComponent.Props), Scope.Scope, scope) ) return React.createElement( @@ -46,15 +46,22 @@ const SuspenseProto = Object.freeze({ export const isSuspense = (u: unknown): u is Suspense => Predicate.hasProperty(u, TypeId) -export const suspense = , P extends {}>( - self: T & Component.Component, any, any> +export const suspense = >( + self: T ): ( - & Omit, Component.Component.Context>> - & Component.Component

, Component.Component.Context> + & Omit> + & Component.Component< + Component.Component.FunctionComponent extends (...args: readonly [infer P, ...infer Args]) => infer A + ? A extends React.ReactNode + ? (...args: readonly [props: P & Suspense.Props, ...Args]) => A + : never + : never, + Component.Component.Error, + Component.Component.Context> & Suspense ) => Object.setPrototypeOf( - Object.assign(function() {}, self, SuspenseProto), - Object.getPrototypeOf(self), + Object.assign(function() {}, self), + Object.freeze({ ...Object.getPrototypeOf(self), ...SuspenseProto }), ) export const withOptions: {