Skip to content

Commit

Permalink
fix: add initialization variables to fix typescript strict mode errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jasonlee6789 committed Sep 30, 2024
1 parent b5f385b commit 5f652d7
Show file tree
Hide file tree
Showing 15 changed files with 47 additions and 40 deletions.
2 changes: 1 addition & 1 deletion ui/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class AppComponent implements OnInit, OnDestroy {

public environment = environment;
public backUrl: string | boolean = "/";
public enableSideMenu: boolean;
public enableSideMenu: boolean = false;
public isSystemLogEnabled: boolean = false;

protected isUserAllowedToSeeOverview: boolean = false;
Expand Down
2 changes: 1 addition & 1 deletion ui/src/app/edge/history/abstracthistorychart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export abstract class AbstractHistoryChart {
borderColor: "rgba(128,128,0,1)",
};

private activeQueryData: string;
private activeQueryData: string = "";
private debounceTimeout: any | null = null;

constructor(
Expand Down
2 changes: 1 addition & 1 deletion ui/src/app/edge/history/abstracthistorywidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { calculateResolution } from "./shared";
// NOTE: Auto-refresh of widgets is currently disabled to reduce server load
export abstract class AbstractHistoryWidget {

private activeQueryData: string;
private activeQueryData: string = "";

//observable is used to fetch new widget data every 5 minutes
// private refreshWidgetData = interval(600000);
Expand Down
2 changes: 1 addition & 1 deletion ui/src/app/edge/history/historydataservice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class HistoryDataService extends DataService {

public queryChannelsTimeout: ReturnType<typeof setTimeout> | null = null;
protected override timestamps: string[] = [];
private activeQueryData: string;
private activeQueryData: string = "";
private channelAddresses: { [sourceId: string]: ChannelAddress } = {};

constructor(
Expand Down
3 changes: 1 addition & 2 deletions ui/src/app/edge/live/common/autarchy/flat/flat.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// @ts-strict-ignore
import { Component } from "@angular/core";
import { AbstractFlatWidget } from "src/app/shared/components/flat/abstract-flat-widget";
import { ChannelAddress, CurrentData, Utils } from "src/app/shared/shared";
Expand All @@ -10,7 +9,7 @@ import { ModalComponent } from "../modal/modal";
})
export class FlatComponent extends AbstractFlatWidget {

public percentageValue: number;
public percentageValue: number = 0;

async presentModal() {
const modal = await this.modalController.create({
Expand Down
4 changes: 2 additions & 2 deletions ui/src/app/edge/live/common/consumption/flat/flat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ export class FlatComponent extends AbstractFlatWidget {
public evcss: EdgeConfig.Component[] | null = null;
public consumptionMeters: EdgeConfig.Component[] | null = null;
public sumActivePower: number = 0;
public evcsSumOfChargePower: number;
public otherPower: number;
public evcsSumOfChargePower: number = 0;
public otherPower: number = 0;
public readonly CONVERT_WATT_TO_KILOWATT = Utils.CONVERT_WATT_TO_KILOWATT;

async presentModal() {
Expand Down
9 changes: 4 additions & 5 deletions ui/src/app/edge/live/common/grid/flat/flat.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// @ts-strict-ignore
import { Component } from "@angular/core";
import { AbstractFlatWidget } from "src/app/shared/components/flat/abstract-flat-widget";
import { Converter } from "src/app/shared/components/shared/converter";
Expand All @@ -20,11 +19,11 @@ export class FlatComponent extends AbstractFlatWidget {
public readonly CONVERT_WATT_TO_KILOWATT = Utils.CONVERT_WATT_TO_KILOWATT;
public readonly GridMode = GridMode;

public gridBuyPower: number;
public gridSellPower: number;
public gridBuyPower: number = 0;
public gridSellPower: number = 0;

protected gridMode: number;
protected gridState: string;
protected gridMode: number = 0;
protected gridState: string = "";
protected icon: Icon | null = null;
protected isActivated: boolean = false;

Expand Down
2 changes: 1 addition & 1 deletion ui/src/app/edge/live/common/selfconsumption/flat/flat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { ModalComponent } from "../modal/modal";
})
export class FlatComponent extends AbstractFlatWidget {

public calculatedSelfConsumption: number;
public calculatedSelfConsumption: number = 0;

async presentModal() {
const modal = await this.modalController.create({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class StorageModalComponent implements OnInit, OnDestroy {
public isLastElement = Utils.isLastElement;

public formGroup: FormGroup = new FormGroup({});
protected isAtLeastInstaller: boolean;
protected isAtLeastInstaller: boolean = false;
protected isTargetTimeInValid: Map<string, boolean> = new Map();
protected controllerIsRequiredEdgeVersion: boolean = false;

Expand Down
2 changes: 1 addition & 1 deletion ui/src/app/shared/components/header/header.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class HeaderComponent implements OnInit, OnDestroy, AfterViewChecked {

public environment = environment;
public backUrl: string | boolean = "/";
public enableSideMenu: boolean;
public enableSideMenu: boolean = false;
public currentPage: "EdgeSettings" | "Other" | "IndexLive" | "IndexHistory" = "Other";
public isSystemLogEnabled: boolean = false;
private ngUnsubscribe: Subject<void> = new Subject<void>();
Expand Down
26 changes: 16 additions & 10 deletions ui/src/app/shared/service/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { environment } from "src/environments";
import { ChartConstants } from "../components/chart/chart.constants";
import { Edge } from "../components/edge/edge";
import { EdgeConfig } from "../components/edge/edgeconfig";
import { JsonrpcResponseError } from "../jsonrpc/base";
import { JsonrpcResponseError, JsonrpcResponseSuccess } from "../jsonrpc/base";
import { GetEdgeRequest } from "../jsonrpc/request/getEdgeRequest";
import { GetEdgesRequest } from "../jsonrpc/request/getEdgesRequest";
import { QueryHistoricTimeseriesEnergyRequest } from "../jsonrpc/request/queryHistoricTimeseriesEnergyRequest";
Expand Down Expand Up @@ -56,12 +56,12 @@ export class Service extends AbstractService {
public deviceWidth: number = 0;
public isSmartphoneResolution: boolean = false;
public isSmartphoneResolutionSubject: Subject<boolean> = new Subject<boolean>();
public activeQueryData: string;
public activeQueryData: string = "";

/**
* Holds the currenty selected Page Title.
*/
public currentPageTitle: string;
public currentPageTitle: string = "";

/**
* Holds reference to Websocket. This is set by Websocket in constructor.
Expand All @@ -70,14 +70,14 @@ export class Service extends AbstractService {
/**
* Holds the currently selected Edge.
*/
public readonly currentEdge: BehaviorSubject<Edge> = new BehaviorSubject<Edge>(null);
public readonly currentEdge: BehaviorSubject<Edge | null> = new BehaviorSubject<Edge | null>(null);

/**
* Holds references of Edge-IDs (=key) to Edge objects (=value)
*/
public readonly metadata: BehaviorSubject<{
user: User, edges: { [edgeId: string]: Edge }
}> = new BehaviorSubject(null);
} | null> = new BehaviorSubject(null);

public currentUser: User | null = null;

Expand All @@ -87,7 +87,7 @@ export class Service extends AbstractService {
private currentActivatedRoute: ActivatedRoute | null = null;

private queryEnergyQueue: {
fromDate: Date, toDate: Date, channels: ChannelAddress[], promises: { resolve, reject }[]
fromDate: Date, toDate: Date, channels: ChannelAddress[], promises: { resolve: (value?: JsonrpcResponseSuccess) => void; reject: (reason: any) => void }[]
}[] = [];
private queryEnergyTimeout: any = null;

Expand All @@ -108,7 +108,9 @@ export class Service extends AbstractService {

// React on Language Change and update language
translate.onLangChange.subscribe((event: LangChangeEvent) => {
this.setLang(Language.getByKey(event.lang));
if (event.lang) {
this.setLang(Language.getByKey(event.lang));
}
});
}

Expand Down Expand Up @@ -197,8 +199,12 @@ export class Service extends AbstractService {
}

public onLogout() {
this.currentEdge.next(null);
this.metadata.next(null);
if (this.currentEdge) {
this.currentEdge.next(null);
}
if (this.metadata) {
this.metadata.next(null);
}
this.websocket.state.set(States.NOT_AUTHENTICATED);
this.router.navigate(["/login"]);
}
Expand Down Expand Up @@ -233,7 +239,7 @@ export class Service extends AbstractService {
fromDate: Date,
toDate: Date,
channels: ChannelAddress[],
promises: { resolve, reject }[];
promises: { resolve: (value: any) => void; reject: (reason: any) => void }[]
}[] = [];

let request;
Expand Down
19 changes: 10 additions & 9 deletions ui/src/app/shared/service/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export class Utils {
*/
public static absSafely(value: number | null): number | null {
if (value == null) {
return value;
return null;
} else {
return Math.abs(value);
}
Expand All @@ -95,7 +95,7 @@ export class Utils {
* @param v1
* @param v2
*/
public static addSafely(v1: number, v2: number): number {
public static addSafely(v1: number | null, v2: number | null): number | null {
if (v1 == null) {
return v2;
} else if (v2 == null) {
Expand All @@ -115,6 +115,7 @@ export class Utils {
return values
.filter(value => value !== null && value !== undefined)
.reduce((sum, curr) => {
if (curr == null) return sum;

Check failure on line 118 in ui/src/app/shared/service/utils.ts

View workflow job for this annotation

GitHub Actions / build-ui

Expected { after 'if' condition
if (sum == null) {
sum = curr;
} else {
Expand Down Expand Up @@ -162,7 +163,7 @@ export class Utils {
* @param v2
* @returns
*/
public static compareArraysSafely<T>(v1: T[] | null, v2: T[] | null): boolean {
public static compareArraysSafely<T>(v1: T[] | null, v2: T[] | null): boolean | null {
if (v1 == null || v2 == null) {
return null;
}
Expand Down Expand Up @@ -215,7 +216,7 @@ export class Utils {
* @param orElse the default value
* @returns the value or the default value
*/
public static orElse(v: number, orElse: number): number {
public static orElse(v: number | null, orElse: number): number {
if (v == null) {
return orElse;
} else {
Expand Down Expand Up @@ -553,7 +554,7 @@ export class Utils {
}

public static isDataEmpty(arg: JsonrpcResponseSuccess): boolean {
return Object.values(arg.result["data"])?.map(element => element as number[])?.every(element => element?.every(elem => elem == null) ?? true);
return Object.values(arg.result["data"] || {})?.map(element => element as number[])?.every(element => element?.every(elem => elem == null) ?? true);
}

/**
Expand Down Expand Up @@ -594,7 +595,7 @@ export class Utils {
* @param consumptionMeterComponents the consumptionMeterComponents
* @returns the other consumption
*/
public static calculateOtherConsumption(channelData: HistoryUtils.ChannelData, evcsComponents: EdgeConfig.Component[], consumptionMeterComponents: EdgeConfig.Component[]): number[] {
public static calculateOtherConsumption(channelData: HistoryUtils.ChannelData, evcsComponents: EdgeConfig.Component[], consumptionMeterComponents: EdgeConfig.Component[]): number[] | null{

const totalEvcsConsumption: number[] = [];
const totalMeteredConsumption: number[] = [];
Expand Down Expand Up @@ -780,14 +781,14 @@ export namespace HistoryUtils {

export namespace ValueConverter {

export const NEGATIVE_AS_ZERO = (value) => {
export const NEGATIVE_AS_ZERO = (value: number | null): number | null => {
if (value == null) {
return null;
}
return Math.max(0, value);
};

export const NON_NEGATIVE = (value) => {
export const NON_NEGATIVE = (value: number | null): number | null => {
if (value >= 0) {
return value;
} else {
Expand Down Expand Up @@ -858,7 +859,7 @@ export namespace TimeOfUseTariffUtils {

// Error handling: Return undefined if value is not valid
if (value === undefined || value === null || Number.isNaN(Number.parseInt(value.toString()))) {
return;
return "";
}

const socLabel = translate.instant("General.soc");
Expand Down
4 changes: 2 additions & 2 deletions ui/src/app/shared/shared.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ export function SubnetmaskValidator(control: FormControl): ValidationErrors {
return /^(255)\.(0|128|192|224|240|248|252|254|255)\.(0|128|192|224|240|248|252|254|255)\.(0|128|192|224|240|248|252|254|255)/.test(control.value) ? null : { "subnetmask": true };
}

export function IpValidatorMessage(err, field: FormlyFieldConfig) {
export function IpValidatorMessage(err: any, field: FormlyFieldConfig) {
return `"${field.formControl.value}" is not a valid IP Address`;
}

export function SubnetmaskValidatorMessage(err, field: FormlyFieldConfig) {
export function SubnetmaskValidatorMessage(err: any, field: FormlyFieldConfig) {
return `"${field.formControl.value}" is not a valid Subnetmask`;
}

Expand Down
4 changes: 2 additions & 2 deletions ui/src/app/shared/type/widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ export type Icon = {
};

export class Widget {
public name: WidgetNature | WidgetFactory | string;
public componentId: string;
public name: WidgetNature | WidgetFactory | string = "";
public componentId: string = "";
}

export class Widgets {
Expand Down
4 changes: 3 additions & 1 deletion ui/src/app/user/user.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,9 @@ export class UserComponent implements OnInit {
public enableAndDisableFormFields(): boolean {

this.userInformationFields = this.userInformationFields.map(field => {
field.props.disabled = !field.props.disabled;
if (field.props) {
field.props.disabled = !field.props.disabled;
}
return field;
});

Expand Down

0 comments on commit 5f652d7

Please sign in to comment.