Skip to content

Commit f270455

Browse files
committed
Use as unknown instead of as any
1 parent 9b9f157 commit f270455

1 file changed

Lines changed: 15 additions & 30 deletions

File tree

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { type ReactNode } from 'react';
21
import { type ComponentHandlerResult } from 'react-chain-of-responsibility/preview';
3-
import ErrorBoundaryForRenderFunction from './ErrorBoundaryForRenderFunction';
2+
import ErrorBoundaryForRenderFunction, {
3+
type ErrorBoundaryForRenderFunctionProps
4+
} from './ErrorBoundaryForRenderFunction';
45
import type templatePolymiddleware from './templatePolymiddleware';
56
import unwrapIfValiError from './unwrapIfValiError';
67

@@ -22,41 +23,25 @@ export default function createErrorBoundaryMiddleware<Request, Props extends {}>
2223

2324
return (
2425
result &&
25-
reactComponent<
26-
// TODO: [P0] Fix unknown.
27-
Props & {
28-
// Need to be unknown here because memo() hid the generic type.
29-
readonly errorBoundaryRenderFunction: (props: unknown) => { render: () => ReactNode };
30-
readonly errorBoundaryWhere: string;
31-
}
32-
>(
33-
ErrorBoundaryForRenderFunction,
34-
// TODO: [P0] Fix any, consider using React context to add extraneous props.
35-
{ errorBoundaryRenderFunction: result?.render, errorBoundaryWhere: where } as any
36-
)
26+
reactComponent(ErrorBoundaryForRenderFunction, {
27+
errorBoundaryRenderFunction: result?.render,
28+
errorBoundaryWhere: where
29+
// TODO: [P1] Fix force casting by using React Context to hide internal props.
30+
} as unknown as ErrorBoundaryForRenderFunctionProps<Props>)
3731
);
3832
} catch (error) {
3933
// Simplify code by re-assigning to `error`.
4034
// eslint-disable-next-line no-ex-assign
4135
error = unwrapIfValiError(error);
4236

4337
// Thrown before render, show the red box immediately.
44-
return reactComponent<
45-
// Need to be unknown here because memo() hid the generic type.
46-
Props & {
47-
readonly errorBoundaryRenderFunction: (props: unknown) => { render: () => ReactNode };
48-
readonly errorBoundaryWhere: string;
49-
}
50-
>(
51-
ErrorBoundaryForRenderFunction,
52-
// TODO: [P0] Fix any, consider using React context to add extraneous props.
53-
{
54-
errorBoundaryRenderFunction: () => {
55-
throw error;
56-
},
57-
errorBoundaryWhere: where
58-
} as any
59-
);
38+
return reactComponent(ErrorBoundaryForRenderFunction, {
39+
errorBoundaryRenderFunction: () => {
40+
throw error;
41+
},
42+
errorBoundaryWhere: where
43+
// TODO: [P1] Fix force casting by using React Context to hide internal props.
44+
} as unknown as ErrorBoundaryForRenderFunctionProps<Props>);
6045
}
6146
});
6247
}

0 commit comments

Comments
 (0)