Skip to content

refactor(types): replace all any in src with shared types/interfaces (closes #85) - #91

Merged
kalwalt merged 2 commits into
devfrom
refactor/85-remove-any-types
Jul 22, 2026
Merged

kalwalt merged 2 commits into
devfrom
refactor/85-remove-any-types

Conversation

@kalwalt

@kalwalt kalwalt commented Jul 21, 2026

Copy link
Copy Markdown
Member

Closes #85. Removes every explicit any from src/ (25 usages across ~9 modules), per the AGENTS.md convention. Types-only — no runtime/behavioral change; the 63-test parity suite is unchanged.

New shared types (src/types.ts)

  • TypedArray = Uint8Array | Int32Array | Float32Array | Float64Array — the buffer-payload union; replaces any on matrix_t.data, pyramid_t levels, and the convol/yape/yape06 helpers.
  • NumericArray = Int32Array | Float32Array | Float64Array — the non-U8 union the linalg kernels use (they never operate on U8 matrices).
  • MotionKernel interface (run/error/check_subset) — replaces kernel: any in motion_estimator, implemented by affine2d/homography2d. get_subset/find_inliers were over-narrowed to the concrete homography2d; widened to MotionKernel (they only use the interface).

Other real types

  • _pool_node_t.next_pool_node_t | null, .bufferArrayBuffer; cache.put_buffer(node: _pool_node_t), cache.allocate(capacity: number).
  • matrix_t.copy_to(other: IMatrix_T), resize(…, ch: number).
  • linalg.svd_decompose(A: matrix_t); pyramid_t.data: matrix_t[]; bound pyrdown/scharr_deriv typed as (src: matrix_t, dst: matrix_t) => void.
  • imgproc.compute_integral_image(dst_tilted: number[]), skindetector(src.data: Uint8Array | Uint8ClampedArray | number[]).

Notes for the reviewer

  • Where widening matrix_t.data to TypedArray met linalg helpers that legitimately exclude U8, the fix is a localized narrowing cast … as NumericArray at 3 sites (lu_solve's ad/bd, the two Jacobi calls) — never as any.
  • Incidental latent-bug fix: data_t's optional 2nd buffer param was any and did buffer.length (an ArrayBuffer has byteLength, not length → the branch would set size = undefined). Typed as ArrayBuffer, corrected to byteLength. The branch is provably unreachable (no caller passes the 2nd arg), so zero behavioral effect — flagging explicitly.
  • Design note: a couple of detector helpers (e.g. _cmp_score_16) were widened from a correct-narrow Uint8Array to the union rather than kept-narrow-plus-cast-at-callsite. Discussed and accepted as-is for now; revisit if it bites.

Verification

tsc --noEmit clean · 0 remaining any in src/ · npm test 63/63 · npm run build-ts succeeds · prettier --check clean.

🤖 Generated with Claude Code

kalwalt and others added 2 commits July 21, 2026 22:27
closes #85)

Removes every explicit `any` from src/ (25 usages across ~9 modules),
per the AGENTS.md convention. No runtime/behavioral change — the 63-test
parity suite is unchanged.

New shared types (src/types.ts):
- `TypedArray = Uint8Array | Int32Array | Float32Array | Float64Array`
  — the buffer-payload union; replaces `any` on `matrix_t.data`,
  `pyramid_t` levels, the convol/yape/yape06 helpers, etc.
- `NumericArray = Int32Array | Float32Array | Float64Array` — the
  non-U8 union the linalg kernels use (they never operate on U8).
- `MotionKernel` interface (`run`/`error`/`check_subset`) — replaces
  `kernel: any` in motion_estimator; implemented by affine2d/homography2d.
  `get_subset`/`find_inliers` were also over-narrowed to the concrete
  `homography2d`; widened to `MotionKernel` (they only use the interface).

Other real types applied:
- `_pool_node_t.next` -> `_pool_node_t | null`; `.buffer` -> `ArrayBuffer`;
  `cache.put_buffer(node)` -> `_pool_node_t`; `cache.allocate(capacity)`
  -> `number`.
- `matrix_t.copy_to(other: IMatrix_T)`, `resize(..., ch: number)`.
- `linalg.svd_decompose(A: matrix_t)`; `pyramid_t.data: matrix_t[]` and
  the bound `pyrdown`/`optical_flow_lk.scharr_deriv` typed as
  `(src: matrix_t, dst: matrix_t) => void`.
- `imgproc.compute_integral_image(dst_tilted: number[])` and
  `skindetector(src.data: Uint8Array | Uint8ClampedArray | number[])`.

Where widening `matrix_t.data` to `TypedArray` met linalg helpers that
legitimately exclude U8, the honest fix was a localized narrowing cast
`... as NumericArray` at the 3 extraction/call sites (lu_solve's ad/bd,
the two Jacobi calls) — not `as any`.

Incidental latent-bug fix: `data_t`'s optional 2nd `buffer` param was
typed `any` and did `buffer.length` (an `ArrayBuffer` has `byteLength`,
not `length`, so the branch would have set `size = undefined`). Typed it
as `ArrayBuffer` and corrected to `byteLength`. This branch is provably
unreachable in the codebase (no caller passes the 2nd arg — `matrix_t`
assigns a `data_t` directly), so there is no behavioral effect; flagging
it explicitly for the reviewer.

Verified: tsc --noEmit clean; 0 remaining `any` in src/; npm test 63/63;
npm run build-ts succeeds; prettier clean.
Format-check failed on CI; a leading blank line had crept into the new
types.ts after the local prettier pass. No code change.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@kalwalt kalwalt self-assigned this Jul 22, 2026
@kalwalt kalwalt added enhancement New feature or request Typescript all about Typescript code design type definitions labels Jul 22, 2026
@kalwalt kalwalt added this to the 1.0.0 milestone Jul 22, 2026
@kalwalt
kalwalt merged commit 071c25e into dev Jul 22, 2026
4 checks passed
@kalwalt
kalwalt deleted the refactor/85-remove-any-types branch July 23, 2026 16:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

code design enhancement New feature or request type definitions Typescript all about Typescript

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Replace remaining any usages with shared types/interfaces (TypedArray, MotionKernel, …)

1 participant