Type filter predicates and colorConfig to eliminate any in filter-config (toward #133)#138
Open
Epi-1120 wants to merge 1 commit intoebi-webcomponents:mainfrom
Open
Conversation
…onfig Remove the implicit-any callback parameters in the filter predicates and the single explicit `any` on `colorConfig` in `src/filter-config.ts`. Callbacks operate at runtime on `TransformedVariant` (= `VariationDatum & Variant`), so the shared `FilterPredicate` signature, `VariantsForFilter` and `countVariantsForFilter` are all tightened to that type. The exported `colorConfig` keeps `(variant: VariationDatum) => string` to match Nightingale's `NightingaleVariation.colorConfig` slot that it is assigned to in `protvista-uniprot.ts`; the narrowing cast is localised inside the function and documented. The existing unit test keeps its intent but upgrades the mock cast to `as unknown as VariantsForFilter` because the hand-built mock shape no longer structurally overlaps with the tightened type. Incremental step toward ebi-webcomponents#133 (scope: `src/filter-config.ts` only, -9 implicit-any errors under `noImplicitAny + strictNullChecks`). Verified with `eslint src`, `vite build`, and `vitest run src/__spec__/filter-config.spec.ts` (5/5 pass).
any in filter-config (toward #133)
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Purpose
Incremental step toward #133 — eliminate implicit and explicit
anyfromsrc/. This PR narrows the scope tosrc/filter-config.tsand its unit test only.Under
tsc --noImplicitAny --strictNullChecksthis file produces 9 implicit-anyerrors (on thefilterPredicatescallbacks and the two innerassociationcallbacks). It also carries the single explicitanyon the exportedcolorConfig. This PR eliminates all 10.Approach
filterPredicatescallbacks receive, at runtime, the transformed variants produced by./adapters/variation-adapter(TransformedVariant = VariationDatum & Variant) — e.g. they readassociation,clinicalSignificances,sourceType, which are onVariantbut not onVariationDatum. Theanywas previously masking this mismatch.FilterPredicatealias and tightenfilterPredicates,VariantsForFilter,getFilteredVariants's callback, andcountVariantsForFilter'svariantparameter toTransformedVariant.colorConfigsignature as(variant: VariationDatum) => stringso it remains assignable toNightingaleVariation.colorConfig(used atsrc/protvista-uniprot.ts:327). The narrowingTransformedVariantcast is localised tocolorConfig's body and documented inline.transformedVariantPositions as VariantsForFilter. WithVariantsForFilternow demanding the richer shape, that single-step cast no longer structurally overlaps (hand-built mocks are intentionally minimal, e.g.begin: numberinstead ofstring). Upgrade it toas unknown as VariantsForFilter— the TypeScript-recommended form — which preserves the test's intent without changing test data or runtime behaviour.Per the issue's guidance to land this incrementally,
noImplicitAny/strictNullChecksand the@typescript-eslint/no-explicit-anyrule are not flipped on yet — that belongs in the closing PR after every directory has been cleaned.Testing
npx eslint src --ext .ts— clean.npx tsc --noEmit --noImplicitAny --strictNullChecks— all 9 previously reported errors fromsrc/filter-config.tsare gone; no new errors surfaced anywhere else (total project errors: 98 → 89).npx vitest run src/__spec__/filter-config.spec.ts— 5/5 tests pass (all fourcolorConfigcolour-per-variant assertions plus thegetFilteredVariantscallback test).npx vite build— successful; declaration emission and bundle unchanged.Visual changes
None — type-system-only change.
Checklist