Skip to content

Commit 9820ec0

Browse files
refactor: convert capture-core-utils and AppStart/unload files from Flow to TypeScript (#4359)
* refactor: convert capture-core-utils and AppStart/unload files from Flow to TypeScript - Convert chunk.js to chunk.ts with proper TypeScript types - Convert WebWorker/index.js to WebWorker/index.ts with type annotations - Convert capture-core-utils/index.js to index.ts and add CaptureClientEvent export - Convert AppStart/unload files from .js to .ts with PlainReduxStore type - Fix ReduxStore interface in AppStart.component.tsx to include getState method - Remove original .js files after creating .ts versions - Maintain minimal changes following TypeScript migration guidelines Co-Authored-By: [email protected] <[email protected]> * fix: resolve SonarCloud code smells in TypeScript conversions - Replace deprecated e.returnValue with e.preventDefault() in beforeunload handler - Convert WebWorker class to factory function to fix constructor return issue - Export both createWebWorker and WebWorker for backward compatibility - Address 'Unexpected class with only a constructor' code smell - Address 'Unexpected return statement in constructor' code smell Co-Authored-By: [email protected] <[email protected]> * fix: update pipe function signature to support zero-argument calls - Use any types to support both zero-argument calls like pipe(...)() Co-Authored-By: [email protected] <[email protected]> * fix: resolve asyncForEach TypeScript error with type assertion - Add type assertion to handle pre-existing asyncForEach extension method - This resolves the final TypeScript compilation error preventing CI from passing Co-Authored-By: [email protected] <[email protected]> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: [email protected] <[email protected]>
1 parent 68f7091 commit 9820ec0

File tree

9 files changed

+20
-20
lines changed

9 files changed

+20
-20
lines changed

src/components/AppStart/AppStart.component.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { theme } from '../../styles/uiTheme';
1515
// Define a basic type for the Redux store
1616
interface ReduxStore {
1717
dispatch: (action: any) => void;
18-
// Add other store properties as needed
18+
getState: () => any;
1919
}
2020

2121
export const AppStart = () => {

src/components/AppStart/unload/addBeforeUnloadEventListener.js renamed to src/components/AppStart/unload/addBeforeUnloadEventListener.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1-
// @flow
21
import { cleanUpCommon } from 'capture-core/cleanUp/cleanUp';
32

3+
type PlainReduxStore = {
4+
dispatch: (action: any) => void;
5+
getState: () => any;
6+
};
7+
48
export function addBeforeUnloadEventListener(store: PlainReduxStore) {
59
window.addEventListener('beforeunload', async (e) => {
610
cleanUpCommon(store);
711

812
if (store.getState().offline.outbox.length > 0) {
913
const msg = 'Unsaved events!';
10-
e.returnValue = msg;
14+
e.preventDefault();
1115
return msg;
1216
}
1317
return undefined;
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
// @flow
21
export { addBeforeUnloadEventListener } from './addBeforeUnloadEventListener';

src/core_modules/capture-core-utils/WebWorker/index.js

Lines changed: 0 additions & 8 deletions
This file was deleted.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export function createWebWorker(worker: string): Worker {
2+
const code = worker.toString();
3+
const blob = new Blob([`(${code})()`]);
4+
return new Worker(URL.createObjectURL(blob));
5+
}
6+
7+
export const WebWorker = createWebWorker;

src/core_modules/capture-core-utils/chunk.js renamed to src/core_modules/capture-core-utils/chunk.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
1-
// @flow
21
function sliceArrayIntoGroups(chunks: number, array: Array<any>, size: number) {
3-
const groups = [];
2+
const groups: Array<any> = [];
43

54
for (let i = 0, j = 0; i < chunks; i += 1, j += size) {
6-
// $FlowFixMe[missing-annot] automated comment
75
groups[i] = array.slice(j, j + size);
86
}
97

108
return groups;
119
}
1210

13-
export function chunk(array: ?Array<any>, size: number) {
11+
export function chunk(array: Array<any> | null | undefined, size: number) {
1412
if (!array || array.length === 0) {
1513
return [];
1614
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
// @flow
21
export { errorCreator } from './errorCreator';
32
export { pipe } from './misc/pipe';
43
export { buildUrl } from './misc';
54
export { makeCancelable as makeCancelablePromise } from './cancelablePromise';
65
export { chunk } from './chunk';
7-
export { WebWorker } from './WebWorker';
6+
export { createWebWorker, WebWorker } from './WebWorker';
87
export { useFeature, featureAvailable, FEATURES } from './featuresSupport';
8+
export type { CaptureClientEvent } from './types/global';
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export const pipe = <T>(...fns: Array<(arg: T, ...args: any[]) => T>) => (x: T, ...args: any[]): T => fns.reduce((v, fn) => fn(v, ...args), x);
1+
export const pipe = (...fns: Array<(arg: any, ...args: any[]) => any>) => (x?: any, ...args: any[]): any => fns.reduce((v, fn) => fn(v, ...args), x);

src/core_modules/capture-core/metaDataStoreLoaders/categories/loadCategories.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,6 @@ export async function loadCategories(
149149

150150
const uniqueCategoryIds = uniqueCategories.map(uc => uc.id);
151151
const categoryIdBatches = chunk(uniqueCategoryIds, 50);
152-
await categoryIdBatches
152+
await (categoryIdBatches as any)
153153
.asyncForEach(idBatch => loadCategoryOptionsInBatchesAsync(idBatch));
154154
}

0 commit comments

Comments
 (0)