From 89db02871164617043a9954908e5038676e76212 Mon Sep 17 00:00:00 2001 From: Hiromasa Ihara Date: Thu, 27 Jun 2024 04:40:35 +0900 Subject: [PATCH] UI: remove ts-strict-ignore for env files and add typing (#2683) --- ui/src/environments/index.ts | 9 +++++---- ui/src/themes/openems/environments/backend-dev.ts | 1 - ui/src/themes/openems/environments/backend-docker.ts | 9 +++++++-- ui/src/themes/openems/environments/backend-prod.ts | 1 - ui/src/themes/openems/environments/edge-dev.ts | 1 - ui/src/themes/openems/environments/edge-docker.ts | 9 +++++++-- ui/src/themes/openems/environments/edge-prod.ts | 1 - ui/src/themes/openems/environments/gitpod.ts | 1 - 8 files changed, 19 insertions(+), 13 deletions(-) diff --git a/ui/src/environments/index.ts b/ui/src/environments/index.ts index d0180b57ae8..8134ed5feee 100644 --- a/ui/src/environments/index.ts +++ b/ui/src/environments/index.ts @@ -21,7 +21,7 @@ export interface Environment { readonly docsUrlPrefix: string; readonly links: { - readonly COMMON_STORAGE: string, + readonly COMMON_STORAGE: string | null, readonly FORGET_PASSWORD: string, readonly EVCS_KEBA_KECONTACT: string, readonly EVCS_HARDY_BARTH: string, @@ -41,8 +41,9 @@ export interface Environment { readonly CONTROLLER_API_REST_READ: string, readonly CONTROLLER_API_REST_READWRITE: string, - readonly SETTINGS_ALERTING: string, - readonly SETTINGS_NETWORK_CONFIGURATION: string, + readonly SETTINGS_ALERTING: string | null, + readonly SETTINGS_NETWORK_CONFIGURATION: string | null, + readonly EVCS_CLUSTER: string, readonly WARRANTY: { readonly HOME: { @@ -89,5 +90,5 @@ export interface Environment { APP_IMAGE: (language: string, appId: string) => string | null; }, }, - readonly PRODUCT_TYPES: (translate: TranslateService) => Filter + readonly PRODUCT_TYPES: (translate: TranslateService) => Filter | null } diff --git a/ui/src/themes/openems/environments/backend-dev.ts b/ui/src/themes/openems/environments/backend-dev.ts index 0f93f985f5d..f48b00c5e42 100644 --- a/ui/src/themes/openems/environments/backend-dev.ts +++ b/ui/src/themes/openems/environments/backend-dev.ts @@ -1,4 +1,3 @@ -// @ts-strict-ignore import { Environment } from "src/environments"; import { theme } from "./theme"; diff --git a/ui/src/themes/openems/environments/backend-docker.ts b/ui/src/themes/openems/environments/backend-docker.ts index 5ca08fb74f8..28c03b27713 100644 --- a/ui/src/themes/openems/environments/backend-docker.ts +++ b/ui/src/themes/openems/environments/backend-docker.ts @@ -1,12 +1,17 @@ -// @ts-strict-ignore import { Environment } from "src/environments"; import { theme } from "./theme"; +// In docker test environment variable window.env is injected. +// cf. +// - tools/docker/ui/root/etc/s6-overlay/s6-rc.d/init-nginx/run +// - tools/docker/ui/assets/env.template.js +const window_env = (window as any).env as { [key: string]: string}; + export const environment: Environment = { ...theme, ...{ backend: 'OpenEMS Backend', - url: window["env"]["websocket"], + url: window_env.websocket, production: true, debugMode: false, diff --git a/ui/src/themes/openems/environments/backend-prod.ts b/ui/src/themes/openems/environments/backend-prod.ts index 114c43274f1..ae5bb5eb32f 100644 --- a/ui/src/themes/openems/environments/backend-prod.ts +++ b/ui/src/themes/openems/environments/backend-prod.ts @@ -1,4 +1,3 @@ -// @ts-strict-ignore import { Environment } from "src/environments"; import { theme } from "./theme"; diff --git a/ui/src/themes/openems/environments/edge-dev.ts b/ui/src/themes/openems/environments/edge-dev.ts index a6fd796b39e..164dd04f34e 100644 --- a/ui/src/themes/openems/environments/edge-dev.ts +++ b/ui/src/themes/openems/environments/edge-dev.ts @@ -1,4 +1,3 @@ -// @ts-strict-ignore import { Environment } from "src/environments"; import { theme } from "./theme"; diff --git a/ui/src/themes/openems/environments/edge-docker.ts b/ui/src/themes/openems/environments/edge-docker.ts index 80ed1d80a99..479b15e852b 100644 --- a/ui/src/themes/openems/environments/edge-docker.ts +++ b/ui/src/themes/openems/environments/edge-docker.ts @@ -1,12 +1,17 @@ -// @ts-strict-ignore import { Environment } from "src/environments"; import { theme } from "./theme"; +// In docker test environment, variable window.env is injected. +// cf. +// - tools/docker/ui/root/etc/s6-overlay/s6-rc.d/init-nginx/run +// - tools/docker/ui/assets/env.template.js +const window_env = (window as any).env as { [key: string]: string}; + export const environment: Environment = { ...theme, ...{ backend: 'OpenEMS Edge', - url: window["env"]["websocket"], + url: window_env.websocket, production: true, debugMode: false, diff --git a/ui/src/themes/openems/environments/edge-prod.ts b/ui/src/themes/openems/environments/edge-prod.ts index 4f023294025..bcaf40f6901 100644 --- a/ui/src/themes/openems/environments/edge-prod.ts +++ b/ui/src/themes/openems/environments/edge-prod.ts @@ -1,4 +1,3 @@ -// @ts-strict-ignore import { Environment } from "src/environments"; import { theme } from "./theme"; diff --git a/ui/src/themes/openems/environments/gitpod.ts b/ui/src/themes/openems/environments/gitpod.ts index 4b8f7f22ead..1ef2f8ca499 100644 --- a/ui/src/themes/openems/environments/gitpod.ts +++ b/ui/src/themes/openems/environments/gitpod.ts @@ -1,4 +1,3 @@ -// @ts-strict-ignore import { Environment } from "src/environments"; import { theme } from "./theme";