Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Start enabling

Manav Rathi2a55215c6262
diff --git a/web/packages/build-config/tsconfig-typecheck.json b/web/packages/build-config/tsconfig-typecheck.json
index ca5722c748..b2cc37216a 100644
--- a/web/packages/build-config/tsconfig-typecheck.json
+++ b/web/packages/build-config/tsconfig-typecheck.json
@@ -60,6 +60,12 @@
/* Ask TypeScript to warn us if we use TypeScript features that cannot
be used by single-file transpilers */
"isolatedModules": true,
+ /* Require sufficient type annotations on exports so that non-tsc tools
+ can trivially (and quickly) generate declaration files */
+ // TODO: [Note: Enable isolatedDeclarations one by one]
+ // "isolatedDeclarations": true,
+ /* Required for isolatedDeclarations */
+ // "composite": true,
/* Enable various workarounds to play better with CJS libraries */
"esModuleInterop": true,
diff --git a/web/packages/utils/array.ts b/web/packages/utils/array.ts
index 0da52c0a30..248100c763 100644
--- a/web/packages/utils/array.ts
+++ b/web/packages/utils/array.ts
@@ -8,7 +8,7 @@
* then we sort by this key. Since the key is random, the sorted array will have
* the original elements in a random order.
*/
-export const shuffled = <T>(xs: T[]) =>
+export const shuffled = <T>(xs: T[]): T[] =>
xs
.map((x) => [Math.random(), x])
.sort()
@@ -24,7 +24,9 @@ export const shuffled = <T>(xs: T[]) =>
* If none of the strings are non-empty, or if there are no strings in the given
* array, return undefined.
*/
-export const firstNonEmpty = (ss: (string | undefined)[]) => {
+export const firstNonEmpty = (
+ ss: (string | undefined)[],
+): string | undefined => {
for (const s of ss) if (s && s.length > 0) return s;
return undefined;
};
@@ -35,7 +37,7 @@ export const firstNonEmpty = (ss: (string | undefined)[]) => {
*
* @param as An array of {@link Uint8Array}.
*/
-export const mergeUint8Arrays = (as: Uint8Array[]) => {
+export const mergeUint8Arrays = (as: Uint8Array[]): Uint8Array => {
// A longer but better performing replacement of
//
// new Uint8Array(as.reduce((acc, x) => acc.concat(...x), []))
diff --git a/web/packages/utils/parse.ts b/web/packages/utils/parse.ts
index 5e0f3c0739..31300a5c4d 100644
--- a/web/packages/utils/parse.ts
+++ b/web/packages/utils/parse.ts
@@ -13,7 +13,7 @@
* >
* > https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/isNaN
*/
-export const maybeParseInt = (s: string) => {
+export const maybeParseInt = (s: string): number | undefined => {
const n = parseInt(s, 10);
return Number.isNaN(n) ? undefined : n;
};
diff --git a/web/packages/utils/promise.ts b/web/packages/utils/promise.ts
index bef7e9819e..e6670d076b 100644
--- a/web/packages/utils/promise.ts
+++ b/web/packages/utils/promise.ts
@@ -4,7 +4,7 @@
* This function is a promisified `setTimeout`. It returns a promise that
* resolves after {@link ms} milliseconds.
*/
-export const wait = (ms: number) =>
+export const wait = (ms: number): Promise<void> =>
new Promise((resolve) => setTimeout(resolve, ms));
/**
@@ -65,7 +65,10 @@ export const wait = (ms: number) =>
* scratch for now. Indeed, I've spent more time writing about the function
* than the function itself.
*/
-export const throttled = (underlying: () => Promise<void>, period: number) => {
+export const throttled = (
+ underlying: () => Promise<void>,
+ period: number,
+): (() => void) => {
let pending = 0;
const f = () => {
@@ -91,7 +94,10 @@ export const throttled = (underlying: () => Promise<void>, period: number) => {
* settled, just its eventual state will be ignored if it gets fullfilled or
* rejected after we've already timed out.
*/
-export const withTimeout = async <T>(promise: Promise<T>, ms: number) => {
+export const withTimeout = async <T>(
+ promise: Promise<T>,
+ ms: number,
+): Promise<T> => {
let timeoutId: ReturnType<typeof setTimeout>;
const rejectOnTimeout = new Promise<T>((_, reject) => {
timeoutId = setTimeout(
diff --git a/web/packages/utils/transform.ts b/web/packages/utils/transform.ts
index 60053b0fae..905977c6d7 100644
--- a/web/packages/utils/transform.ts
+++ b/web/packages/utils/transform.ts
@@ -7,9 +7,9 @@ export const nullToUndefined = <T>(v: T | null | undefined): T | undefined =>
/**
* Convert `null` and `undefined` to `0`, passthrough everything else unchanged.
*/
-export const nullishToZero = (v: number | null | undefined) => v ?? 0;
+export const nullishToZero = (v: number | null | undefined): number => v ?? 0;
/**
* Convert `null` and `undefined` to `[]`, passthrough everything else unchanged.
*/
-export const nullishToEmpty = <T>(v: T[] | null | undefined) => v ?? [];
+export const nullishToEmpty = <T>(v: T[] | null | undefined): T[] => v ?? [];
diff --git a/web/packages/utils/tsconfig.json b/web/packages/utils/tsconfig.json
index 36e7d7e94b..d3340b2f7b 100644
--- a/web/packages/utils/tsconfig.json
+++ b/web/packages/utils/tsconfig.json
@@ -1 +1,6 @@
-{ "extends": "@/build-config/tsconfig-typecheck.json", "include": ["."] }
+{
+ "extends": "@/build-config/tsconfig-typecheck.json",
+ // TODO: [Note: Enable isolatedDeclarations one by one]
+ "compilerOptions": { "isolatedDeclarations": true, "composite": true },
+ "include": ["."]
+}