From c442c45a2c0f2fcf504bf0455a83ff09444786be Mon Sep 17 00:00:00 2001 From: Kirk Swenson Date: Sat, 13 Jul 2024 15:56:51 -0700 Subject: [PATCH] chore: eliminate unnecessary casts after `filter()` due to TS 5.5 improved type inference --- v3/src/components/case-table/use-rows.ts | 2 +- v3/src/components/case-table/use-selected-rows.ts | 2 +- v3/src/models/data/collection.ts | 4 ++-- v3/src/models/formula/attribute-formula-adapter.ts | 4 ++-- v3/src/models/formula/formula-observers.ts | 8 ++++---- v3/src/models/shared/shared-data-utils.ts | 4 ++-- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/v3/src/components/case-table/use-rows.ts b/v3/src/components/case-table/use-rows.ts index de20900556..b93aae1476 100644 --- a/v3/src/components/case-table/use-rows.ts +++ b/v3/src/components/case-table/use-rows.ts @@ -55,7 +55,7 @@ export const useRows = () => { const parentId = row?.[symParent] const isCollapsed = parentId && caseMetadata?.isCollapsed(parentId) return !isCollapsed || row?.[symFirstChild] ? row : undefined - }).filter(c => !!c) as TRow[] + }).filter(c => !!c) }) prf.measure("Table.useRows[syncRowsToRdg-set]", () => { collectionTableModel.resetRows(newRows || []) diff --git a/v3/src/components/case-table/use-selected-rows.ts b/v3/src/components/case-table/use-selected-rows.ts index c8acc5f688..19e43bbe8f 100644 --- a/v3/src/components/case-table/use-selected-rows.ts +++ b/v3/src/components/case-table/use-selected-rows.ts @@ -93,7 +93,7 @@ export const useSelectedRows = ({ gridRef, onScrollClosestRowIntoView }: UseSele if (isPartialSelectionAction(action)) { const caseIds = action.args[0] const caseIndices = caseIds.map(id => collectionCaseIndexFromId(id, data, collectionId)) - .filter(index => index != null) as number[] + .filter(index => index != null) const isSelecting = ((action.name === "selectCases") && action.args[1]) || true isSelecting && caseIndices.length && onScrollClosestRowIntoView(collectionId, caseIndices) } diff --git a/v3/src/models/data/collection.ts b/v3/src/models/data/collection.ts index 9d5e18edc0..3a2619ea15 100644 --- a/v3/src/models/data/collection.ts +++ b/v3/src/models/data/collection.ts @@ -251,12 +251,12 @@ export const CollectionModel = V2Model const caseGroups = self.caseIds .map(caseId => self.getCaseGroup(caseId)) - .filter(group => !!group) as CaseGroup[] + .filter(group => !!group) runInAction(() => _caseGroups.set(caseGroups)) const cases = self.caseIds .map(caseId => self.getCaseGroup(caseId)?.groupedCase) - .filter(groupedCase => !!groupedCase) as IGroupedCase[] + .filter(groupedCase => !!groupedCase) runInAction(() => _cases.set(cases)) } } diff --git a/v3/src/models/formula/attribute-formula-adapter.ts b/v3/src/models/formula/attribute-formula-adapter.ts index b74e3befd8..f97dad8504 100644 --- a/v3/src/models/formula/attribute-formula-adapter.ts +++ b/v3/src/models/formula/attribute-formula-adapter.ts @@ -242,7 +242,7 @@ export class AttributeFormulaAdapter implements IFormulaManagerAdapter { const formulaDependencies = getFormulaDependencies(formula.canonical, attributeId) const localDatasetAttributeDependencies: ILocalAttributeDependency[] = - formulaDependencies.filter(d => d.type === "localAttribute") as ILocalAttributeDependency[] + formulaDependencies.filter(d => d.type === "localAttribute") for (const dependency of localDatasetAttributeDependencies) { const dependencyAttribute = dataSet.attrFromID(dependency.attrId) if (isValidFormulaAttr(dependencyAttribute)) { @@ -251,7 +251,7 @@ export class AttributeFormulaAdapter implements IFormulaManagerAdapter { } const lookupDependencies: ILookupDependency[] = - formulaDependencies.filter(d => d.type === "lookup") as ILookupDependency[] + formulaDependencies.filter(d => d.type === "lookup") for (const dependency of lookupDependencies) { const externalDataSet = dataSets.get(dependency.dataSetId) const dependencyAttribute = externalDataSet?.attrFromID(dependency.attrId) diff --git a/v3/src/models/formula/formula-observers.ts b/v3/src/models/formula/formula-observers.ts index 3b80aea22e..cade363834 100644 --- a/v3/src/models/formula/formula-observers.ts +++ b/v3/src/models/formula/formula-observers.ts @@ -3,7 +3,7 @@ import { onAnyAction } from "../../utilities/mst-utils" import { IDataSet } from "../data/data-set" import { AddCasesAction, SetCaseValuesAction } from "../data/data-set-actions" import { - CaseList, IFormulaDependency, IGlobalValueDependency, ILocalAttributeDependency, ILookupDependency + CaseList, IFormulaDependency, ILocalAttributeDependency, ILookupDependency } from "./formula-types" import { IGlobalValueManager } from "../global/global-value-manager" import { ICase } from "../data/data-set-types" @@ -23,7 +23,7 @@ export const getLocalAttrCasesToRecalculate = (cases: ICase[], formulaDependenci export const observeLocalAttributes = (formulaDependencies: IFormulaDependency[], localDataSet: IDataSet, recalculateCallback: (casesToRecalculate: CaseList) => void) => { const localAttrDependencies = - formulaDependencies.filter(d => d.type === "localAttribute") as ILocalAttributeDependency[] + formulaDependencies.filter(d => d.type === "localAttribute") const anyAggregateDepPresent = localAttrDependencies.some(d => d.aggregate) @@ -60,7 +60,7 @@ export const getLookupCasesToRecalculate = (cases: ICase[], dependency: ILookupD export const observeLookupDependencies = (formulaDependencies: IFormulaDependency[], dataSets: Map, recalculateCallback: (casesToRecalculate: CaseList) => void) => { const lookupDependencies: ILookupDependency[] = - formulaDependencies.filter(d => d.type === "lookup") as ILookupDependency[] + formulaDependencies.filter(d => d.type === "lookup") const disposeLookupObserver = lookupDependencies.map(dependency => { const externalDataSet = dataSets.get(dependency.dataSetId) @@ -100,7 +100,7 @@ export const observeLookupDependencies = (formulaDependencies: IFormulaDependenc export const observeGlobalValues = (formulaDependencies: IFormulaDependency[], globalValueManager: IGlobalValueManager | undefined, recalculateCallback: (casesToRecalculate: CaseList) => void) => { - const globalValueDependencies = formulaDependencies.filter(d => d.type === "globalValue") as IGlobalValueDependency[] + const globalValueDependencies = formulaDependencies.filter(d => d.type === "globalValue") const disposeGlobalValueObserver = globalValueDependencies.map(dependency => // Recalculate formula when global value dependency is updated. reaction( diff --git a/v3/src/models/shared/shared-data-utils.ts b/v3/src/models/shared/shared-data-utils.ts index aac3382322..8d38f8daf6 100644 --- a/v3/src/models/shared/shared-data-utils.ts +++ b/v3/src/models/shared/shared-data-utils.ts @@ -42,7 +42,7 @@ export function getTileDataSet(tile: ITileContentModel): IDataSet | undefined { } export function getAllTileDataSets(tile: ITileContentModel): ISharedDataSet[] { - return getTileSharedModels(tile).filter(m => isSharedDataSet(m)) as ISharedDataSet[] + return getTileSharedModels(tile).filter(m => isSharedDataSet(m)) } export function getTileCaseMetadata(tile: ITileContentModel) { @@ -51,7 +51,7 @@ export function getTileCaseMetadata(tile: ITileContentModel) { } export function getAllTileCaseMetadata(tile: ITileContentModel): ISharedCaseMetadata[] { - return getTileSharedModels(tile).filter(m => isSharedCaseMetadata(m)) as ISharedCaseMetadata[] + return getTileSharedModels(tile).filter(m => isSharedCaseMetadata(m)) } export function isTileLinkedToDataSet(tile: ITileContentModel, dataSet: IDataSet) {