From fd1908f9a0890e949df3aac4e7490afa1e541a41 Mon Sep 17 00:00:00 2001 From: Kenrick Tandrian <60643640+KenTandrian@users.noreply.github.com> Date: Sun, 30 Aug 2026 21:47:47 +0700 Subject: [PATCH] Task/improve Angular template type safety in client (#7763) * feat(client): resolve type errors * feat(client): enable strict safe navigation types * feat(client): resolve type errors * feat(ui): resolve type errors * feat(client): default to default locale --- .../asset-profile-dialog/asset-profile-dialog.html | 8 ++++---- .../admin-settings/admin-settings.component.html | 4 ++-- .../components/admin-settings/admin-settings.component.ts | 3 +++ .../components/home-holdings/home-holdings.component.ts | 3 +++ .../src/app/components/home-holdings/home-holdings.html | 6 +++--- .../components/home-watchlist/home-watchlist.component.ts | 2 ++ .../src/app/components/home-watchlist/home-watchlist.html | 2 +- .../src/app/components/markets/markets.component.ts | 3 +++ apps/client/src/app/components/markets/markets.html | 2 +- .../portfolio-performance.component.html | 2 +- .../portfolio-summary/portfolio-summary.component.html | 8 ++++---- .../src/app/pages/accounts/accounts-page.component.ts | 3 +++ apps/client/src/app/pages/accounts/accounts-page.html | 4 ++-- .../create-or-update-activity-dialog.component.ts | 2 ++ .../create-or-update-activity-dialog.html | 2 +- .../app/pages/portfolio/allocations/allocations-page.html | 8 +++++--- .../user-account-registration-dialog.html | 2 +- apps/client/tsconfig.json | 2 +- .../benchmark-detail-dialog/benchmark-detail-dialog.html | 2 +- libs/ui/src/lib/line-chart/line-chart.component.ts | 8 ++++++-- 20 files changed, 49 insertions(+), 27 deletions(-) diff --git a/apps/client/src/app/components/admin-market-data/asset-profile-dialog/asset-profile-dialog.html b/apps/client/src/app/components/admin-market-data/asset-profile-dialog/asset-profile-dialog.html index a68768ff1..7e4a0c2f1 100644 --- a/apps/client/src/app/components/admin-market-data/asset-profile-dialog/asset-profile-dialog.html +++ b/apps/client/src/app/components/admin-market-data/asset-profile-dialog/asset-profile-dialog.html @@ -71,10 +71,10 @@ type="button" [disabled]=" !canDeleteAssetProfile({ - activitiesCount: assetProfile?.activitiesCount, + activitiesCount: assetProfile?.activitiesCount ?? 0, isBenchmark: isBenchmark, symbol: data.symbol, - watchedByCount: assetProfile?.watchedByCount + watchedByCount: assetProfile?.watchedByCount ?? 0 }) " (click)=" @@ -272,8 +272,8 @@ > @if ( - assetProfile?.countries?.length > 0 || - assetProfile?.sectors?.length > 0 + (assetProfile?.countries?.length ?? 0) > 0 || + (assetProfile?.sectors?.length ?? 0) > 0 ) { @if ( assetProfile?.countries?.length === 1 && diff --git a/apps/client/src/app/components/admin-settings/admin-settings.component.html b/apps/client/src/app/components/admin-settings/admin-settings.component.html index 260aac002..9d15a6a76 100644 --- a/apps/client/src/app/components/admin-settings/admin-settings.component.html +++ b/apps/client/src/app/components/admin-settings/admin-settings.component.html @@ -230,13 +230,13 @@

Platforms

- +

Tags

- +
diff --git a/apps/client/src/app/components/admin-settings/admin-settings.component.ts b/apps/client/src/app/components/admin-settings/admin-settings.component.ts index 5080e9f85..b0c3dc2d2 100644 --- a/apps/client/src/app/components/admin-settings/admin-settings.component.ts +++ b/apps/client/src/app/components/admin-settings/admin-settings.component.ts @@ -3,6 +3,7 @@ import { GfAdminTagComponent } from '@ghostfolio/client/components/admin-tag/adm import { GfDataProviderStatusComponent } from '@ghostfolio/client/components/data-provider-status/data-provider-status.component'; import { UserService } from '@ghostfolio/client/services/user/user.service'; import { + DEFAULT_LOCALE, E_MAIL_LINE_BREAK, PROPERTY_API_KEY_GHOSTFOLIO } from '@ghostfolio/common/config'; @@ -98,6 +99,8 @@ export class GfAdminSettingsComponent implements OnInit { public pricingUrl: string; public user: User; + protected readonly DEFAULT_LOCALE = DEFAULT_LOCALE; + public constructor( private adminService: AdminService, private changeDetectorRef: ChangeDetectorRef, diff --git a/apps/client/src/app/components/home-holdings/home-holdings.component.ts b/apps/client/src/app/components/home-holdings/home-holdings.component.ts index 34b672bc3..7f02cfb64 100644 --- a/apps/client/src/app/components/home-holdings/home-holdings.component.ts +++ b/apps/client/src/app/components/home-holdings/home-holdings.component.ts @@ -1,4 +1,5 @@ import { UserService } from '@ghostfolio/client/services/user/user.service'; +import { DEFAULT_LOCALE } from '@ghostfolio/common/config'; import { AssetProfileIdentifier, PortfolioPosition, @@ -50,6 +51,8 @@ import { DeviceDetectorService } from 'ngx-device-detector'; export class GfHomeHoldingsComponent implements OnInit { public static DEFAULT_HOLDINGS_VIEW_MODE: HoldingsViewMode = 'TABLE'; + protected readonly DEFAULT_LOCALE = DEFAULT_LOCALE; + protected deviceType: string; protected hasPermissionToAccessHoldingsChart: boolean; protected hasPermissionToCreateActivity: boolean; diff --git a/apps/client/src/app/components/home-holdings/home-holdings.html b/apps/client/src/app/components/home-holdings/home-holdings.html index 5c6a95d8e..df6d57c0e 100644 --- a/apps/client/src/app/components/home-holdings/home-holdings.html +++ b/apps/client/src/app/components/home-holdings/home-holdings.html @@ -37,11 +37,11 @@ }
- @if (hasPermissionToCreateActivity && holdings?.length > 0) { + @if (hasPermissionToCreateActivity && (holdings?.length ?? 0) > 0) {
(undefined); protected readonly deviceType = computed( diff --git a/apps/client/src/app/components/markets/markets.html b/apps/client/src/app/components/markets/markets.html index d834dfd0e..68b22d26f 100644 --- a/apps/client/src/app/components/markets/markets.html +++ b/apps/client/src/app/components/markets/markets.html @@ -52,7 +52,7 @@ diff --git a/apps/client/src/app/components/portfolio-performance/portfolio-performance.component.html b/apps/client/src/app/components/portfolio-performance/portfolio-performance.component.html index d6339a5ff..8aeb0c433 100644 --- a/apps/client/src/app/components/portfolio-performance/portfolio-performance.component.html +++ b/apps/client/src/app/components/portfolio-performance/portfolio-performance.component.html @@ -1,7 +1,7 @@
- @if (errors()?.length > 0 && !isLoading()) { + @if ((errors()?.length ?? 0) > 0 && !isLoading()) { Holdings @if ( !hasImpersonationId && - summary?.totalValueInBaseCurrency > 0 && + (summary?.totalValueInBaseCurrency ?? 0) > 0 && user?.settings?.isExperimentalFeatures ) { Cash @if ( !hasImpersonationId && - summary?.totalValueInBaseCurrency > 0 && + (summary?.totalValueInBaseCurrency ?? 0) > 0 && user?.settings?.isExperimentalFeatures ) { Excluded from Analysis @if ( !hasImpersonationId && - summary?.totalValueInBaseCurrency > 0 && + (summary?.totalValueInBaseCurrency ?? 0) > 0 && user?.settings?.isExperimentalFeatures ) { Emergency Fund @if ( !hasImpersonationId && - summary?.totalValueInBaseCurrency > 0 && + (summary?.totalValueInBaseCurrency ?? 0) > 0 && user?.settings?.isExperimentalFeatures ) {

Accounts

@@ -236,7 +238,7 @@ >Other Markets
- @if (markets?.[UNKNOWN_KEY]?.valueInPercentage > 0) { + @if ((markets?.[UNKNOWN_KEY]?.valueInPercentage ?? 0) > 0) {
diff --git a/apps/client/tsconfig.json b/apps/client/tsconfig.json index 48c367749..2899fc61c 100644 --- a/apps/client/tsconfig.json +++ b/apps/client/tsconfig.json @@ -25,7 +25,7 @@ "strictLiteralTypes": true, "strictNullInputTypes": true, "strictOutputEventTypes": true, - "strictSafeNavigationTypes": false, + "strictSafeNavigationTypes": true, // TODO: Enable stricter rules for this project "strictTemplates": false }, diff --git a/libs/ui/src/lib/benchmark/benchmark-detail-dialog/benchmark-detail-dialog.html b/libs/ui/src/lib/benchmark/benchmark-detail-dialog/benchmark-detail-dialog.html index 3ff7f03ab..2f415d874 100644 --- a/libs/ui/src/lib/benchmark/benchmark-detail-dialog/benchmark-detail-dialog.html +++ b/libs/ui/src/lib/benchmark/benchmark-detail-dialog/benchmark-detail-dialog.html @@ -1,7 +1,7 @@ diff --git a/libs/ui/src/lib/line-chart/line-chart.component.ts b/libs/ui/src/lib/line-chart/line-chart.component.ts index edc377fa3..5dbb6cc31 100644 --- a/libs/ui/src/lib/line-chart/line-chart.component.ts +++ b/libs/ui/src/lib/line-chart/line-chart.component.ts @@ -4,7 +4,11 @@ import { getValueAxisOptions, getVerticalHoverLinePlugin } from '@ghostfolio/common/chart-helper'; -import { primaryColorRgb, secondaryColorRgb } from '@ghostfolio/common/config'; +import { + DEFAULT_COLOR_SCHEME, + primaryColorRgb, + secondaryColorRgb +} from '@ghostfolio/common/config'; import { getBackgroundColor, getLocale } from '@ghostfolio/common/helper'; import { LineChartItem } from '@ghostfolio/common/interfaces'; import { ColorScheme } from '@ghostfolio/common/types'; @@ -52,7 +56,7 @@ export class GfLineChartComponent { @Input() benchmarkDataItems: LineChartItem[] = []; @Input() benchmarkLabel = ''; - @Input() colorScheme: ColorScheme; + @Input() colorScheme: ColorScheme = DEFAULT_COLOR_SCHEME; @Input() currency: string; @Input() historicalDataItems: LineChartItem[]; @Input() isAnimated = false;