mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-24 15:31:13 -05:00
Fix: Resolve type errors in page components
This commit is contained in:
22
src/lib/typeAssertions.ts
Normal file
22
src/lib/typeAssertions.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* Type assertion helpers for TypeScript strict mode compatibility
|
||||
* These help bridge database types (null) with application types (undefined)
|
||||
*/
|
||||
|
||||
export function nullToUndefined<T>(value: T | null): T | undefined {
|
||||
return value === null ? undefined : value;
|
||||
}
|
||||
|
||||
export function convertNullsToUndefined<T extends Record<string, any>>(obj: T): { [K in keyof T]: T[K] extends (infer U | null) ? (U | undefined) : T[K] } {
|
||||
const result: any = {};
|
||||
for (const key in obj) {
|
||||
const value = obj[key];
|
||||
result[key] = value === null ? undefined : value;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// Type guard for checking if value is not null/undefined
|
||||
export function isDefined<T>(value: T | null | undefined): value is T {
|
||||
return value !== null && value !== undefined;
|
||||
}
|
||||
Reference in New Issue
Block a user