4
4
useEffect ,
5
5
Component ,
6
6
type FunctionComponent ,
7
+ type ReactElement ,
7
8
} from "react" ;
8
9
import React from "react" ;
9
10
import jsxRuntime from "react/jsx-runtime" ;
@@ -44,7 +45,11 @@ const ProxyHandlers = {
44
45
*
45
46
* @see https://github.com/facebook/react/blob/2d80a0cd690bb5650b6c8a6c079a87b5dc42bd15/packages/react-reconciler/src/ReactFiberHooks.old.js#L460
46
47
*/
47
- apply ( Component : FunctionComponent , thisArg : any , argumentsList : any ) {
48
+ apply (
49
+ Component : FunctionComponent < any > ,
50
+ thisArg : any ,
51
+ argumentsList : Parameters < FunctionComponent < any > >
52
+ ) {
48
53
const store = useMemo ( createEffectStore , Empty ) ;
49
54
50
55
useSyncExternalStore ( store . subscribe , store . getSnapshot , store . getSnapshot ) ;
@@ -54,6 +59,7 @@ const ProxyHandlers = {
54
59
try {
55
60
const children = Component . apply ( thisArg , argumentsList ) ;
56
61
return children ;
62
+ // eslint-disable-next-line no-useless-catch
57
63
} catch ( e ) {
58
64
// Re-throwing promises that'll be handled by suspense
59
65
// or an actual error.
@@ -69,6 +75,7 @@ const ProxyHandlers = {
69
75
function ProxyFunctionalComponent ( Component : FunctionComponent < any > ) {
70
76
return ProxyInstance . get ( Component ) || WrapWithProxy ( Component ) ;
71
77
}
78
+
72
79
function WrapWithProxy ( Component : FunctionComponent < any > ) {
73
80
if ( SupportsProxy ) {
74
81
const ProxyComponent = new Proxy ( Component , ProxyHandlers ) ;
@@ -93,9 +100,10 @@ function WrapWithProxy(Component: FunctionComponent<any>) {
93
100
* el.type.defaultProps;
94
101
* ```
95
102
*/
96
- const WrappedComponent = function ( ) {
97
- return ProxyHandlers . apply ( Component , undefined , arguments ) ;
103
+ const WrappedComponent : FunctionComponent < any > = ( ... args ) => {
104
+ return ProxyHandlers . apply ( Component , undefined , args ) ;
98
105
} ;
106
+
99
107
ProxyInstance . set ( Component , WrappedComponent ) ;
100
108
ProxyInstance . set ( WrappedComponent , WrappedComponent ) ;
101
109
@@ -204,6 +212,12 @@ JsxPro.jsxs && /* */ (JsxPro.jsxs = WrapJsx(JsxPro.jsxs));
204
212
JsxDev . jsxDEV && /**/ ( JsxDev . jsxDEV = WrapJsx ( JsxDev . jsxDEV ) ) ;
205
213
JsxPro . jsxDEV && /**/ ( JsxPro . jsxDEV = WrapJsx ( JsxPro . jsxDEV ) ) ;
206
214
215
+ declare module "@preact/signals-core" {
216
+ // @ts -ignore internal Signal is viewed as function
217
+ // eslint-disable-next-line @typescript-eslint/no-empty-interface
218
+ interface Signal extends ReactElement { }
219
+ }
220
+
207
221
/**
208
222
* A wrapper component that renders a Signal's value directly as a Text node.
209
223
*/
0 commit comments