Skip to content

Commit 0eb42bd

Browse files
committed
refactor(laroux): add return types to various functions for improved type safety
- Updated error response functions in api-types.ts to explicitly define return types. - Enhanced build error functions in types.ts with return types for better clarity. - Added return type annotations to createIsolatedWriter in build-validator.ts. - Specified return types for methods in error-boundary.tsx, error-overlay.tsx, lazy-loader.ts, image.tsx, and renderer.ts for consistency and type safety.
1 parent 9ecfe30 commit 0eb42bd

File tree

9 files changed

+39
-20
lines changed

9 files changed

+39
-20
lines changed

pkg/@eser/laroux-bundler/domain/build-validator.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,11 +196,19 @@ export function isWithinOutputDir(
196196
resolvedFilePath === resolvedDistDir;
197197
}
198198

199+
/**
200+
* Isolated writer interface for build output
201+
*/
202+
export type IsolatedWriter = {
203+
writeTextFile(filePath: string, content: string): Promise<void>;
204+
copy(src: string, dest: string): Promise<void>;
205+
};
206+
199207
/**
200208
* Create a safe write function that only allows writes to dist/
201209
* Use this to wrap file writes for strict isolation
202210
*/
203-
export function createIsolatedWriter(distDir: string) {
211+
export function createIsolatedWriter(distDir: string): IsolatedWriter {
204212
const resolvedDistDir = runtime.path.resolve(distDir);
205213

206214
return {

pkg/@eser/laroux-bundler/types.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,23 +91,23 @@ export class BuildError extends Error {
9191
*/
9292
export const buildErrors = {
9393
/** CSS processing error */
94-
cssError: (reason: string) =>
94+
cssError: (reason: string): BuildError =>
9595
new BuildError(
9696
`CSS processing failed: ${reason}`,
9797
"BUILD104",
9898
"Check your CSS files and configuration.",
9999
),
100100

101101
/** Module not found */
102-
moduleNotFound: (modulePath: string) =>
102+
moduleNotFound: (modulePath: string): BuildError =>
103103
new BuildError(
104104
`Module not found: ${modulePath}`,
105105
"BUILD100",
106106
"Check that the file exists and the import path is correct.",
107107
),
108108

109109
/** Build failed */
110-
buildFailed: (reason: string) =>
110+
buildFailed: (reason: string): BuildError =>
111111
new BuildError(
112112
`Build failed: ${reason}`,
113113
"BUILD101",

pkg/@eser/laroux-react/client/bootstrap/error-boundary.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,12 @@ export class ErrorBoundary extends Component<Props, State> {
6969
});
7070
}
7171

72-
handleRetry = () => {
72+
handleRetry = (): void => {
7373
// Reload the page to retry
7474
globalThis.location.reload();
7575
};
7676

77-
render() {
77+
render(): React.ReactNode {
7878
if (this.state.hasError) {
7979
// For network errors, don't show visible error UI - just return null
8080
// This keeps SSR content visible and prevents Lighthouse score penalty

pkg/@eser/laroux-react/client/bootstrap/error-overlay.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ interface ErrorInfo {
1616
column?: number;
1717
}
1818

19-
export function ErrorOverlay() {
19+
export function ErrorOverlay(): React.ReactElement | null {
2020
const [error, setError] = useState<ErrorInfo | null>(null);
2121

2222
useEffect(() => {

pkg/@eser/laroux-react/client/bootstrap/lazy-loader.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,12 @@ export class LazyChunkLoader {
336336
/**
337337
* Get loading statistics (for debugging)
338338
*/
339-
getStats() {
339+
getStats(): {
340+
totalChunks: number;
341+
loadedChunks: number;
342+
loadingChunks: number;
343+
cachedModules: number;
344+
} {
340345
return {
341346
totalChunks: Object.keys(this.manifest.files).length,
342347
loadedChunks: this.loadedChunks.size,

pkg/@eser/laroux-react/runtime/image/image.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export { ImageSizes };
3737
* - Decoding async for better performance
3838
* - fetchpriority for above-the-fold images
3939
*/
40-
export function Image(props: ImageProps) {
40+
export function Image(props: ImageProps): React.ReactElement {
4141
const {
4242
src,
4343
fallback,
@@ -113,7 +113,9 @@ export function Image(props: ImageProps) {
113113
* Server Component - Responsive image with aspect ratio container
114114
* Prevents layout shift with CSS aspect-ratio
115115
*/
116-
export function ResponsiveImage(props: ResponsiveImageProps) {
116+
export function ResponsiveImage(
117+
props: ResponsiveImageProps,
118+
): React.ReactElement {
117119
const {
118120
src,
119121
alt,

pkg/@eser/laroux-server/adapters/react/html-shell.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,4 +150,5 @@ export function createReactHtmlShellBuilder(): HtmlShellBuilder {
150150
/**
151151
* Default React HTML shell builder instance
152152
*/
153-
export const reactHtmlShellBuilder = createReactHtmlShellBuilder();
153+
export const reactHtmlShellBuilder: HtmlShellBuilder =
154+
createReactHtmlShellBuilder();

pkg/@eser/laroux-server/adapters/react/renderer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,4 +149,4 @@ export function createReactRenderer(): Renderer {
149149
/**
150150
* Default React renderer instance
151151
*/
152-
export const reactRenderer = createReactRenderer();
152+
export const reactRenderer: Renderer = createReactRenderer();

pkg/@eser/laroux/router/api-types.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,17 @@ export function errorResponse(
9595
* Standard HTTP error responses
9696
*/
9797
export const HttpError = {
98-
badRequest: (message = "Bad Request") => errorResponse(message, 400),
99-
unauthorized: (message = "Unauthorized") => errorResponse(message, 401),
100-
forbidden: (message = "Forbidden") => errorResponse(message, 403),
101-
notFound: (message = "Not Found") => errorResponse(message, 404),
102-
methodNotAllowed: (message = "Method Not Allowed") =>
98+
badRequest: (message = "Bad Request"): Response =>
99+
errorResponse(message, 400),
100+
unauthorized: (message = "Unauthorized"): Response =>
101+
errorResponse(message, 401),
102+
forbidden: (message = "Forbidden"): Response => errorResponse(message, 403),
103+
notFound: (message = "Not Found"): Response => errorResponse(message, 404),
104+
methodNotAllowed: (message = "Method Not Allowed"): Response =>
103105
errorResponse(message, 405),
104-
conflict: (message = "Conflict") => errorResponse(message, 409),
105-
unprocessable: (message = "Unprocessable Entity") =>
106+
conflict: (message = "Conflict"): Response => errorResponse(message, 409),
107+
unprocessable: (message = "Unprocessable Entity"): Response =>
106108
errorResponse(message, 422),
107-
internal: (message = "Internal Server Error") => errorResponse(message, 500),
109+
internal: (message = "Internal Server Error"): Response =>
110+
errorResponse(message, 500),
108111
};

0 commit comments

Comments
 (0)