Fix typescript compilation error on public properties

Signed-off-by: Bryan Frimin <bryan@getprobo.com>
Signed-off-by: Sacha Al Himdani <sacha@getprobo.com>
This commit is contained in:
Jonathan
2025-06-11 18:42:10 +02:00
committed by Sacha Al Himdani
parent 155bbbd840
commit fb9bce0282

View File

@@ -8,7 +8,11 @@ import {
const DEFAULT_STORAGE_KEY = "reactLazyReloadedFunctions"; const DEFAULT_STORAGE_KEY = "reactLazyReloadedFunctions";
class ReloadStorage { class ReloadStorage {
constructor(public readonly storageKey = DEFAULT_STORAGE_KEY) {} public readonly storageKey: string;
constructor(storageKey = DEFAULT_STORAGE_KEY) {
this.storageKey = storageKey;
}
getMap(): Map<string, number> { getMap(): Map<string, number> {
const stored = sessionStorage.getItem(this.storageKey); const stored = sessionStorage.getItem(this.storageKey);
@@ -21,9 +25,9 @@ class ReloadStorage {
(value) => (value) =>
Array.isArray(value) && Array.isArray(value) &&
typeof value[0] === "string" && typeof value[0] === "string" &&
typeof value[1] === "number" typeof value[1] === "number",
) )
: [] : [],
); );
} catch (error) { } catch (error) {
console.error("Error parsing react-lazy storage:", error); console.error("Error parsing react-lazy storage:", error);
@@ -46,7 +50,7 @@ class ReloadStorage {
protected save(stored: Map<string, number>): void { protected save(stored: Map<string, number>): void {
sessionStorage.setItem( sessionStorage.setItem(
this.storageKey, this.storageKey,
JSON.stringify([...stored.entries()]) JSON.stringify([...stored.entries()]),
); );
} }
} }
@@ -85,7 +89,9 @@ const createConfig = (init: LazyConfigInit = {}): LazyConfig => ({
? Math.max(0, init.importRetries) ? Math.max(0, init.importRetries)
: 0, : 0,
retryDelay: retryDelay:
typeof init.retryDelay === "number" ? Math.max(0, init.retryDelay) : 300, typeof init.retryDelay === "number"
? Math.max(0, init.retryDelay)
: 300,
onImportError: init.onImportError, onImportError: init.onImportError,
}); });
@@ -95,14 +101,16 @@ export function createLazy<P = {}>(config: LazyConfigInit = {}) {
const reloadStorage = new ReloadStorage(forceReload.storageKey); const reloadStorage = new ReloadStorage(forceReload.storageKey);
function enhancedLazy<T = P>( function enhancedLazy<T = P>(
importFunction: () => Promise<{ default: ComponentType<T> }> importFunction: () => Promise<{ default: ComponentType<T> }>,
): LazyExoticComponent<ComponentType<T>> { ): LazyExoticComponent<ComponentType<T>> {
const functionString = importFunction.toString(); const functionString = importFunction.toString();
const importWithRetry = async () => { const importWithRetry = async () => {
let retryCount = 0; let retryCount = 0;
const tryImport = async (): Promise<{ default: ComponentType<T> }> => { const tryImport = async (): Promise<{
default: ComponentType<T>;
}> => {
try { try {
return await importFunction(); return await importFunction();
} catch (error) { } catch (error) {
@@ -116,7 +124,9 @@ export function createLazy<P = {}>(config: LazyConfigInit = {}) {
retryCount++; retryCount++;
if (retryDelay > 0) { if (retryDelay > 0) {
await new Promise((resolve) => setTimeout(resolve, retryDelay)); await new Promise((resolve) =>
setTimeout(resolve, retryDelay),
);
} }
return tryImport(); return tryImport();