Skip to content

A local-first personal finance app

Correct type for `to-budget` field (#3237)

Julian Dominguez-Schatzd1362c3d741c
diff --git a/packages/desktop-client/src/components/budget/rollover/budgetsummary/ToBudget.tsx b/packages/desktop-client/src/components/budget/rollover/budgetsummary/ToBudget.tsx
index 3a13460b8c..a925f0d519 100644
--- a/packages/desktop-client/src/components/budget/rollover/budgetsummary/ToBudget.tsx
+++ b/packages/desktop-client/src/components/budget/rollover/budgetsummary/ToBudget.tsx
@@ -36,7 +36,7 @@ export function ToBudget({
value: 0,
});
const availableValue = sheetValue;
- if (typeof availableValue !== 'number') {
+ if (typeof availableValue !== 'number' && availableValue !== null) {
throw new Error(
'Expected availableValue to be a number but got ' + availableValue,
);
@@ -83,7 +83,7 @@ export function ToBudget({
)}
{menuOpen === 'transfer' && (
<TransferMenu
- initialAmount={availableValue}
+ initialAmount={availableValue ?? undefined}
onClose={() => setMenuOpen(null)}
onSubmit={(amount, categoryId) => {
onBudgetAction(month, 'transfer-available', {
diff --git a/packages/desktop-client/src/components/budget/rollover/budgetsummary/ToBudgetAmount.tsx b/packages/desktop-client/src/components/budget/rollover/budgetsummary/ToBudgetAmount.tsx
index befa001806..36a055bd9b 100644
--- a/packages/desktop-client/src/components/budget/rollover/budgetsummary/ToBudgetAmount.tsx
+++ b/packages/desktop-client/src/components/budget/rollover/budgetsummary/ToBudgetAmount.tsx
@@ -39,12 +39,12 @@ export function ToBudgetAmount({
});
const format = useFormat();
const availableValue = sheetValue;
- if (typeof availableValue !== 'number') {
+ if (typeof availableValue !== 'number' && availableValue !== null) {
throw new Error(
'Expected availableValue to be a number but got ' + availableValue,
);
}
- const num = isNaN(availableValue) ? 0 : availableValue;
+ const num = availableValue ?? 0;
const isNegative = num < 0;
return (
diff --git a/tsconfig.json b/tsconfig.json
index d7a3fae83d..59f6d0d4bd 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -7,11 +7,7 @@
"compilerOptions": {
// "composite": true,
"target": "ES2022",
- "lib": [
- "ES2022",
- "DOM",
- "DOM.Iterable"
- ],
+ "lib": ["ES2022", "DOM", "DOM.Iterable"],
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"experimentalDecorators": true,
@@ -23,10 +19,7 @@
"noFallthroughCasesInSwitch": true,
"skipLibCheck": true,
"jsx": "preserve",
- "types": [
- "vite/client",
- "jest"
- ],
+ "types": ["vite/client", "jest"],
// Check JS files too
"allowJs": true,
"checkJs": false,
@@ -38,33 +31,27 @@
"noEmit": true,
"paths": {
// until we turn on composite/references
- "loot-core/*": [
- "./packages/loot-core/src/*"
- ],
+ "loot-core/*": ["./packages/loot-core/src/*"],
},
"plugins": [
{
"name": "typescript-strict-plugin",
- "path": [
- "./packages"
- ]
- }
- ]
+ "path": ["./packages"],
+ },
+ ],
},
- "include": [
- "packages/**/*"
- ],
+ "include": ["packages/**/*"],
"exclude": [
"node_modules",
"**/node_modules/*",
"**/build/*",
"**/client-build/*",
"**/dist/*",
- "**/lib-dist/*"
+ "**/lib-dist/*",
],
"ts-node": {
"compilerOptions": {
- "module": "CommonJS"
- }
- }
+ "module": "CommonJS",
+ },
+ },
}
diff --git a/upcoming-release-notes/3237.md b/upcoming-release-notes/3237.md
new file mode 100644
index 0000000000..9f4a10697e
--- /dev/null
+++ b/upcoming-release-notes/3237.md
@@ -0,0 +1,6 @@
+---
+category: Bugfix
+authors: [jfdoming]
+---
+
+Fix crash when visiting later months