Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: decrease using type of any to get typing benefit #2704

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions ui/src/app/changelog/view/component/changelog.constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@
public static readonly OPENEMS_BACKEND = new Product('OpenEMS Edge', 'https://github.com/OpenEMS/openems');

// private to disallow creating other instances of this type
private constructor(public readonly name: string, public readonly url: any) {
private constructor(public readonly name: string, public readonly url: string) {
}
}

export class App {
// private to disallow creating other instances of this type
private constructor(public readonly name: string, public readonly url: any) {
private constructor(public readonly name: string, public readonly url: string) {

Check warning on line 46 in ui/src/app/changelog/view/component/changelog.constants.ts

View check run for this annotation

Codecov / codecov/patch

ui/src/app/changelog/view/component/changelog.constants.ts#L46

Added line #L46 was not covered by tests
}
}

Expand All @@ -52,7 +52,7 @@
public static readonly SDM630_ZAEHLER = new OpenemsComponent('SDM 630 Zähler', 'https://github.com/OpenEMS/openems/tree/develop/io.openems.edge.meter.microcare.sdm630');

// private to disallow creating other instances of this type
private constructor(public readonly name: string, public readonly url: any) {
private constructor(public readonly name: string, public readonly url: string) {
}
}

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 @@ -13,7 +13,7 @@
@Injectable()
export class HistoryDataService extends DataService {

public queryChannelsTimeout: any | null = null;
public queryChannelsTimeout: ReturnType<typeof setTimeout> | null = null;

Check warning on line 16 in ui/src/app/edge/history/historydataservice.ts

View check run for this annotation

Codecov / codecov/patch

ui/src/app/edge/history/historydataservice.ts#L16

Added line #L16 was not covered by tests
protected override timestamps: string[] = [];
private channelAddresses: { [sourceId: string]: ChannelAddress } = {};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class FlatComponent extends AbstractFlatWidget implements OnInit {

protected readonly CONVERT_MODE_TO_MANUAL_OFF_AUTOMATIC = Utils.CONVERT_MODE_TO_MANUAL_OFF_AUTOMATIC(this.translate);
protected readonly CONVERT_TIME_OF_USE_TARIFF_STATE = Utils.CONVERT_TIME_OF_USE_TARIFF_STATE(this.translate);
protected priceWithCurrency: any;
protected priceWithCurrency: string;

async presentModal() {
const modal = await this.modalController.create({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { Controller_Ess_TimeOfUseTariff } from '../Ess_TimeOfUseTariff';
export class ModalComponent extends AbstractModal {

protected readonly CONVERT_TIME_OF_USE_TARIFF_STATE = this.Utils.CONVERT_TIME_OF_USE_TARIFF_STATE(this.translate);
protected priceWithCurrency: any;
protected priceWithCurrency: string;

protected override getFormGroup(): FormGroup {
return this.formBuilder.group({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class EvcsChartComponent implements OnInit, OnChanges {

public loading: boolean = true;
public options: BarChartOptions;
public labels: any[];
public labels: string[];
public datasets: Chart.ChartDataset[];
public chart: Chart.Chart; // This will hold our chart info

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,12 +278,12 @@ export abstract class AbstractSection {
}

/**
* calculate...
* ...length of square and image;
* ...x and y of text and image;
* ...fontsize of text;
*/
private getSquare(innerRadius: any): SvgSquare {
* calculate...
* ...length of square and image;
* ...x and y of text and image;
* ...fontsize of text;
*/
private getSquare(innerRadius: number): SvgSquare {
const width = innerRadius / 2.5;

const textSize = width / 4;
Expand Down
6 changes: 3 additions & 3 deletions ui/src/app/shared/components/pickdate/pickdate.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@
}

case DefaultTypes.PeriodString.CUSTOM: {
let dateDistance = Math.floor(Math.abs(<any>this.service.historyPeriod.value.from - <any>this.service.historyPeriod.value.to) / (1000 * 60 * 60 * 24));
let dateDistance = Math.floor(Math.abs(this.service.historyPeriod.value.from.getTime() - this.service.historyPeriod.value.to.getTime()) / (1000 * 60 * 60 * 24));

Check warning on line 179 in ui/src/app/shared/components/pickdate/pickdate.component.ts

View check run for this annotation

Codecov / codecov/patch

ui/src/app/shared/components/pickdate/pickdate.component.ts#L179

Added line #L179 was not covered by tests
if (dateDistance == 0) {
dateDistance = 1;
}
Expand Down Expand Up @@ -271,7 +271,7 @@
break;
}
case DefaultTypes.PeriodString.CUSTOM: {
let dateDistance = Math.floor(Math.abs(<any>this.service.historyPeriod.value.from - <any>this.service.historyPeriod.value.to) / (1000 * 60 * 60 * 24));
let dateDistance = Math.floor(Math.abs(this.service.historyPeriod.value.from.getTime() - this.service.historyPeriod.value.to.getTime()) / (1000 * 60 * 60 * 24));

Check warning on line 274 in ui/src/app/shared/components/pickdate/pickdate.component.ts

View check run for this annotation

Codecov / codecov/patch

ui/src/app/shared/components/pickdate/pickdate.component.ts#L274

Added line #L274 was not covered by tests
if (dateDistance == 0) {
dateDistance = 1;
}
Expand Down Expand Up @@ -322,7 +322,7 @@
break;
}
case DefaultTypes.PeriodString.CUSTOM: {
let dateDistance = Math.floor(Math.abs(<any>this.service.historyPeriod.value.from - <any>this.service.historyPeriod.value.to) / (1000 * 60 * 60 * 24));
let dateDistance = Math.floor(Math.abs(this.service.historyPeriod.value.from.getTime() - this.service.historyPeriod.value.to.getTime()) / (1000 * 60 * 60 * 24));

Check warning on line 325 in ui/src/app/shared/components/pickdate/pickdate.component.ts

View check run for this annotation

Codecov / codecov/patch

ui/src/app/shared/components/pickdate/pickdate.component.ts#L325

Added line #L325 was not covered by tests
if (dateDistance == 0) {
dateDistance = 1;
}
Expand Down
2 changes: 1 addition & 1 deletion ui/src/app/shared/service/arrayutils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export namespace ArrayUtils {
export function equalsCheck(a: any[], b: any[]) {
export function equalsCheck<T>(a: T[], b: T[]) {
return a.length === b.length &&
a.every((v, i) => v === b[i]);
}
Expand Down
2 changes: 2 additions & 0 deletions ui/src/app/shared/service/myerrorhandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ export class MyErrorHandler implements ErrorHandler {
private injector: Injector,
) { }

// https://v16.angular.io/api/core/ErrorHandler#errorhandler
// eslint-disable-next-line @typescript-eslint/no-explicit-any
handleError(error: any) {
const logger = this.injector.get(Logger);
console.error(error);
Expand Down
2 changes: 2 additions & 0 deletions ui/src/app/shared/service/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ export class Service extends AbstractService {
this.notificationEvent.next(notification);
}

// https://v16.angular.io/api/core/ErrorHandler#errorhandler
// eslint-disable-next-line @typescript-eslint/no-explicit-any
public override handleError(error: any) {
console.error(error);
// TODO: show notification
Expand Down
2 changes: 2 additions & 0 deletions ui/src/app/shared/service/test/dummyservice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ export class DummyService extends AbstractService {
isPartnerAllowed(edge: Edge): boolean {
throw new Error("Method not implemented.");
}
// https://v16.angular.io/api/core/ErrorHandler#errorhandler
// eslint-disable-next-line @typescript-eslint/no-explicit-any
override handleError(error: any): void {
throw new Error("Method not implemented.");
}
Expand Down
22 changes: 11 additions & 11 deletions ui/src/app/shared/service/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@
* @param element
* @param array
*/
public static isLastElement(element, array: any[]) {
public static isLastElement<T>(element: T, array: T[]): boolean {
return element == array[array.length - 1];
}

/**
* Creates a deep copy of the object
*/
public static deepCopy(obj: any, target?: any) {
public static deepCopy<T>(obj: T, target?: T): T {
let copy: any;

// Handle the 3 simple types, and null or undefined
Expand Down Expand Up @@ -162,7 +162,7 @@
* @param v2
* @returns
*/
public static compareArraysSafely(v1: any[], v2: any[]): boolean {
public static compareArraysSafely<T>(v1: T[] | null, v2: T[] | null): boolean {
if (v1 == null || v2 == null) {
return null;
}
Expand Down Expand Up @@ -236,7 +236,7 @@
* @param value the value from passed value in html
* @returns converted value
*/
public static CONVERT_TO_WATT = (value: any): string => {
public static CONVERT_TO_WATT = (value: number | null): string => {
if (value == null) {
return '-';
} else if (value >= 0) {
Expand All @@ -252,7 +252,7 @@
* @param value the value from passed value in html
* @returns converted value
*/
public static CONVERT_WATT_TO_KILOWATT = (value: any): string => {
public static CONVERT_WATT_TO_KILOWATT = (value: number | null): string => {
if (value == null) {
return '-';
}
Expand All @@ -271,7 +271,7 @@
* @param value the value from passed value in html
* @returns converted value
*/
public static CONVERT_SECONDS_TO_DATE_FORMAT = (value: any): string => {
public static CONVERT_SECONDS_TO_DATE_FORMAT = (value: number): string => {
return new Date(value * 1000).toLocaleTimeString();
};

Expand All @@ -291,7 +291,7 @@
* @param value the value from passed value in html
* @returns converted value
*/
public static CONVERT_TO_WATTHOURS = (value: any): string => {
public static CONVERT_TO_WATTHOURS = (value: number): string => {
return formatNumber(value, 'de', '1.0-1') + ' Wh';
};

Expand All @@ -301,7 +301,7 @@
* @param value the value from passed value in html
* @returns converted value
*/
public static CONVERT_TO_KILO_WATTHOURS = (value: any): string => {
public static CONVERT_TO_KILO_WATTHOURS = (value: number): string => {
return formatNumber(Utils.divideSafely(value, 1000), 'de', '1.0-1') + ' kWh';
};

Expand Down Expand Up @@ -381,7 +381,7 @@
* @returns converted value
*/
public static CONVERT_PRICE_TO_CENT_PER_KWH = (decimal: number, label: string) => {
return (value: any): string =>
return (value: number | null): string =>

Check warning on line 384 in ui/src/app/shared/service/utils.ts

View check run for this annotation

Codecov / codecov/patch

ui/src/app/shared/service/utils.ts#L384

Added line #L384 was not covered by tests
(!value ? "-" : formatNumber(value / 10, 'de', '1.0-' + decimal)) + ' ' + label;
};

Expand Down Expand Up @@ -517,7 +517,7 @@
* @param array the array to be shuffled
* @returns the shuffled array
*/
public static shuffleArray(array: any[]): any[] {
public static shuffleArray<T>(array: T[]): T[] {
return array.sort(() => Math.random() - 0.5);
}

Expand All @@ -529,7 +529,7 @@
* @param source the source Object.
* @returns the value.
*/
public static isArrayExistingInSource(arrayToCheck: string[], source: any): boolean {
public static isArrayExistingInSource(arrayToCheck: string[], source: Record<string, any>): boolean {
return arrayToCheck.every(value => {
if (value in source) {
return true;
Expand Down
10 changes: 8 additions & 2 deletions ui/src/app/shared/type/language.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@ import fr from 'src/assets/i18n/fr.json';
import nl from 'src/assets/i18n/nl.json';
import ja from 'src/assets/i18n/ja.json';

interface Translation {
[key: string]: string | Translation;
}

export class MyTranslateLoader implements TranslateLoader {

public getTranslation(key: string): Observable<any> {
public getTranslation(key: string): Observable<Translation> {
const language = Language.getByKey(key);
if (language) {
return of(language.json);
Expand All @@ -43,6 +47,9 @@ export class Language {
public readonly key: string,
public readonly i18nLocaleKey: string,
public readonly json: any,
// Angular is not providing common type for locale.
// https://github.com/angular/angular/issues/30506
// eslint-disable-next-line @typescript-eslint/no-explicit-any
public readonly locale: any,
) {
}
Expand Down Expand Up @@ -100,5 +107,4 @@ export class Language {

return lang?.i18nLocaleKey ?? Language.DEFAULT.i18nLocaleKey;
}

}
2 changes: 1 addition & 1 deletion ui/src/app/shared/utils/array/array.utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export namespace ArrayUtils {
export function equalsCheck(a: any[], b: any[]) {
export function equalsCheck<T>(a: T[], b: T[]): boolean {
return a.length === b.length &&
a.every((v, i) => v === b[i]);
}
Expand Down
2 changes: 2 additions & 0 deletions ui/src/zone-flags.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/**
* Prevents Angular change detection from
* running with certain Web Component callbacks
* https://ionicframework.com/docs/ja/troubleshooting/runtime#angular-change-detection
*/
// eslint-disable-next-line no-underscore-dangle
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(window as any).__Zone_disable_customElements = true;