use for-of statements to replace for and for-in

This commit is contained in:
MaysWind
2025-09-14 01:40:53 +08:00
parent 67bc81d3e2
commit 4700446ca0
38 changed files with 389 additions and 597 deletions
+15 -27
View File
@@ -108,7 +108,7 @@ export class Account implements AccountInfoResponse {
}
for (let i = 0; i < this.subAccounts.length; i++) {
if (!this.subAccounts[i].equals(other.subAccounts[i])) {
if (!(this.subAccounts[i] as Account).equals(other.subAccounts[i] as Account)) {
return false;
}
}
@@ -137,9 +137,9 @@ export class Account implements AccountInfoResponse {
public setSuitableIcon(oldCategory: number, newCategory: number): void {
const allCategories = AccountCategory.values();
for (let i = 0; i < allCategories.length; i++) {
if (allCategories[i].type === oldCategory) {
if (this.icon !== allCategories[i].defaultAccountIconId) {
for (const category of allCategories) {
if (category.type === oldCategory) {
if (this.icon !== category.defaultAccountIconId) {
return;
} else {
break;
@@ -147,9 +147,9 @@ export class Account implements AccountInfoResponse {
}
}
for (let i = 0; i < allCategories.length; i++) {
if (allCategories[i].type === newCategory) {
this.icon = allCategories[i].defaultAccountIconId;
for (const category of allCategories) {
if (category.type === newCategory) {
this.icon = category.defaultAccountIconId;
}
}
}
@@ -231,9 +231,7 @@ export class Account implements AccountInfoResponse {
return null;
}
for (let i = 0; i < this.subAccounts.length; i++) {
const subAccount = this.subAccounts[i];
for (const subAccount of this.subAccounts) {
if (subAccountId && subAccountId === subAccount.id) {
return subAccount.id;
}
@@ -255,9 +253,7 @@ export class Account implements AccountInfoResponse {
return false;
}
for (let i = 0; i < this.subAccounts.length; i++) {
const subAccount = this.subAccounts[i];
for (const subAccount of this.subAccounts) {
if (subAccountId && subAccountId === subAccount.id) {
return subAccount.hidden;
}
@@ -279,9 +275,7 @@ export class Account implements AccountInfoResponse {
return null;
}
for (let i = 0; i < this.subAccounts.length; i++) {
const subAccount = this.subAccounts[i];
for (const subAccount of this.subAccounts) {
if (subAccountId && subAccountId === subAccount.id) {
return subAccount.comment;
}
@@ -303,9 +297,7 @@ export class Account implements AccountInfoResponse {
return null;
}
for (let i = 0; i < this.subAccounts.length; i++) {
const subAccount = this.subAccounts[i];
for (const subAccount of this.subAccounts) {
if (subAccountId && subAccountId === subAccount.id) {
return subAccount;
}
@@ -322,9 +314,7 @@ export class Account implements AccountInfoResponse {
return null;
}
for (let i = 0; i < this.subAccounts.length; i++) {
const subAccount = this.subAccounts[i];
for (const subAccount of this.subAccounts) {
if (subAccountId && subAccountId === subAccount.id) {
return subAccount;
}
@@ -341,9 +331,7 @@ export class Account implements AccountInfoResponse {
const subAccountCurrenciesMap: Record<string, boolean> = {};
const subAccountCurrencies: string[] = [];
for (let i = 0; i < this.subAccounts.length; i++) {
const subAccount = this.subAccounts[i];
for (const subAccount of this.subAccounts) {
if (!showHidden && subAccount.hidden) {
continue;
}
@@ -508,7 +496,7 @@ export class Account implements AccountInfoResponse {
if (account1.parentId && account1.parentId !== '0') {
if (allAccountsMap && allAccountsMap[account1.parentId]) {
account1DisplayOrder = allAccountsMap[account1.parentId].displayOrder;
account1DisplayOrder = (allAccountsMap[account1.parentId] as Account).displayOrder;
} else {
account1DisplayOrder = null;
}
@@ -516,7 +504,7 @@ export class Account implements AccountInfoResponse {
if (account2.parentId && account2.parentId !== '0') {
if (allAccountsMap && allAccountsMap[account2.parentId]) {
account2DisplayOrder = allAccountsMap[account2.parentId].displayOrder;
account2DisplayOrder = (allAccountsMap[account2.parentId] as Account).displayOrder;
} else {
account2DisplayOrder = null;
}
+4 -4
View File
@@ -1,4 +1,4 @@
import type { PartialRecord } from '@/core/base.ts';
import { type PartialRecord, itemAndIndex } from '@/core/base.ts';
import type { Year1BasedMonth, TextualYearMonthDay, StartEndTime, WeekDay } from '@/core/datetime.ts';
import { type Coordinate, getNormalizedCoordinate } from '@/core/coordinate.ts';
import { TransactionType } from '@/core/transaction.ts';
@@ -185,9 +185,9 @@ export class Transaction implements TransactionInfoResponse {
return;
}
for (let i = 0; i < this._pictures.length; i++) {
if (this._pictures[i].pictureId === pictureInfo.pictureId) {
this._pictures.splice(i, 1);
for (const [picture, index] of itemAndIndex(this._pictures)) {
if (picture.pictureId === pictureInfo.pictureId) {
this._pictures.splice(index, 1);
}
}
}
+4 -7
View File
@@ -1,3 +1,4 @@
import { entries } from '@/core/base.ts';
import type { ColorValue } from '@/core/color.ts';
import { CategoryType } from '@/core/category.ts';
import { DEFAULT_CATEGORY_ICON_ID } from '@/consts/icon.ts';
@@ -58,7 +59,7 @@ export class TransactionCategory implements TransactionCategoryInfoResponse {
}
for (let i = 0; i < this.subCategories.length; i++) {
if (!this.subCategories[i].equals(other.subCategories[i])) {
if (!(this.subCategories[i] as TransactionCategory).equals(other.subCategories[i] as TransactionCategory)) {
return false;
}
}
@@ -132,12 +133,8 @@ export class TransactionCategory implements TransactionCategoryInfoResponse {
public static ofMap(categoriesByType: Record<number, TransactionCategoryInfoResponse[]>): Record<number, TransactionCategory[]> {
const ret: Record<number, TransactionCategory[]> = {};
for (const categoryType in categoriesByType) {
if (!Object.prototype.hasOwnProperty.call(categoriesByType, categoryType)) {
continue;
}
ret[categoryType] = TransactionCategory.ofMulti(categoriesByType[categoryType]);
for (const [categoryType, categories] of entries(categoriesByType)) {
ret[parseInt(categoryType)] = TransactionCategory.ofMulti(categories);
}
return ret;