Skip to content

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
Epi-1120:refactor/filter-config-no-implicit-any
Open

Type filter predicates and colorConfig to eliminate any in filter-config (toward #133)#138
Epi-1120 wants to merge 1 commit intoebi-webcomponents:mainfrom
Epi-1120:refactor/filter-config-no-implicit-any

Conversation

@Epi-1120
Copy link
Copy Markdown

Purpose

Incremental step toward #133 — eliminate implicit and explicit any from src/. This PR narrows the scope to src/filter-config.ts and its unit test only.

Under tsc --noImplicitAny --strictNullChecks this file produces 9 implicit-any errors (on the filterPredicates callbacks and the two inner association callbacks). It also carries the single explicit any on the exported colorConfig. This PR eliminates all 10.

Approach

  • The filterPredicates callbacks receive, at runtime, the transformed variants produced by ./adapters/variation-adapter (TransformedVariant = VariationDatum & Variant) — e.g. they read association, clinicalSignificances, sourceType, which are on Variant but not on VariationDatum. The any was previously masking this mismatch.
  • Introduce a local FilterPredicate alias and tighten filterPredicates, VariantsForFilter, getFilteredVariants's callback, and countVariantsForFilter's variant parameter to TransformedVariant.
  • Keep the exported colorConfig signature as (variant: VariationDatum) => string so it remains assignable to NightingaleVariation.colorConfig (used at src/protvista-uniprot.ts:327). The narrowing TransformedVariant cast is localised to colorConfig's body and documented inline.
  • The existing unit test already uses transformedVariantPositions as VariantsForFilter. With VariantsForFilter now demanding the richer shape, that single-step cast no longer structurally overlaps (hand-built mocks are intentionally minimal, e.g. begin: number instead of string). Upgrade it to as 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/strictNullChecks and the @typescript-eslint/no-explicit-any rule 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 from src/filter-config.ts are 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 four colorConfig colour-per-variant assertions plus the getFilteredVariants callback test).
  • npx vite build — successful; declaration emission and bundle unchanged.

Visual changes

None — type-system-only change.

Checklist

  • My PR is scoped properly, and "does one thing only"
  • I have reviewed my own code
  • I have checked that linting checks pass and type safety is respected
  • I have checked that tests pass and coverage has at least improved, and if not explained the reasons why
  • If needed, the changes have been previewed by all interested parties.

…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).
@Epi-1120 Epi-1120 changed the title Type filter predicates and colorConfig to eliminate ny in filter-config (toward #133) Type filter predicates and colorConfig to eliminate any in filter-config (toward #133) Apr 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant