refactor(types): replace all any in src with shared types/interfaces (closes #85) - #91
Merged
Merged
Conversation
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>
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.
Closes #85. Removes every explicit
anyfromsrc/(25 usages across ~9 modules), per theAGENTS.mdconvention. 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; replacesanyonmatrix_t.data,pyramid_tlevels, and the convol/yape/yape06 helpers.NumericArray=Int32Array | Float32Array | Float64Array— the non-U8 union the linalg kernels use (they never operate on U8 matrices).MotionKernelinterface (run/error/check_subset) — replaceskernel: anyinmotion_estimator, implemented byaffine2d/homography2d.get_subset/find_inlierswere over-narrowed to the concretehomography2d; widened toMotionKernel(they only use the interface).Other real types
_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[]; boundpyrdown/scharr_derivtyped 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
matrix_t.datatoTypedArraymet linalg helpers that legitimately exclude U8, the fix is a localized narrowing cast… as NumericArrayat 3 sites (lu_solve'sad/bd, the two Jacobi calls) — neveras any.data_t's optional 2ndbufferparam wasanyand didbuffer.length(anArrayBufferhasbyteLength, notlength→ the branch would setsize = undefined). Typed asArrayBuffer, corrected tobyteLength. The branch is provably unreachable (no caller passes the 2nd arg), so zero behavioral effect — flagging explicitly._cmp_score_16) were widened from a correct-narrowUint8Arrayto the union rather than kept-narrow-plus-cast-at-callsite. Discussed and accepted as-is for now; revisit if it bites.Verification
tsc --noEmitclean · 0 remaininganyinsrc/·npm test63/63 ·npm run build-tssucceeds ·prettier --checkclean.🤖 Generated with Claude Code