Skip to content

Commit

Permalink
chore: eliminate unnecessary casts after filter() due to TS 5.5 imp…
Browse files Browse the repository at this point in the history
…roved type inference
  • Loading branch information
kswenson committed Jul 13, 2024
1 parent 7846fbd commit c442c45
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion v3/src/components/case-table/use-rows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 || [])
Expand Down
2 changes: 1 addition & 1 deletion v3/src/components/case-table/use-selected-rows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions v3/src/models/data/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
Expand Down
4 changes: 2 additions & 2 deletions v3/src/models/formula/attribute-formula-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions v3/src/models/formula/formula-observers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)

Expand Down Expand Up @@ -60,7 +60,7 @@ export const getLookupCasesToRecalculate = (cases: ICase[], dependency: ILookupD
export const observeLookupDependencies = (formulaDependencies: IFormulaDependency[], dataSets: Map<string, IDataSet>,
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)
Expand Down Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions v3/src/models/shared/shared-data-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down

0 comments on commit c442c45

Please sign in to comment.