Summary
The .ts source still contains ~25 uses of any (across ~9 modules). Most map to a small set of real shapes — introducing a few shared type aliases/interfaces would eliminate the majority and improve type safety, editor autocomplete and refactor safety.
Environment
- Product/Service:
src/**/*.ts (excluding generated types/**/*.d.ts)
- Version: post-0.9.0 (
dev)
- Constraint:
tsconfig runs strict: true but strictNullChecks: false and noImplicitAny: true — so these are all explicit anys, not inferred ones.
Actual state (inventory)
Grouped by the underlying real type, most-impactful first:
1. Typed-array payloads → a shared TypedArray alias
The recurring one. matrix_t.data, pyramid_t.data, pool buffers etc. are always one of Uint8Array | Int32Array | Float32Array | Float64Array.
src/matrix_t/matrix_t.ts:19,63 — data: any (interface + class)
src/matrix_t/matrix_t.ts:25,27 — copy_to(other: any), resize(..., ch: any)
src/pyramid_t/pyramid_t.ts:17,59 — data: any, b: any = this.data[0]
src/node_utils/data_t.ts:44 — buffer?: any
src/node_utils/_pool_node_t.ts:22 — buffer: any
src/imgproc/imgproc.ts:698 — dst_tilted: any[]
src/optical_flow_lk/optical_flow_lk.ts:18 — scharr_deriv: any
2. Cache pool node → _pool_node_t
src/cache/cache.ts:13,85 — put_buffer(node: any) (interface + impl); the node is a _pool_node_t
src/node_utils/_pool_node_t.ts:16 — next: any (self-referential _pool_node_t)
3. Motion-model kernel → a MotionKernel interface
motion_estimator.ransac/lmeds take kernel: any; the real contract is { run(from, to, model, count): number; error(...): void; check_subset(...): boolean }, implemented by affine2d/homography2d.
src/motion_estimator/motion_estimator.ts:137,250 — kernel: any
4. Point-subset scratch arrays → point_t[]
src/motion_estimator/motion_estimator.ts:156,157,270,271 — subset0/1: any = []
5. matrix_t args typed loosely → matrix_t
src/linalg/linalg.ts:605 — svd_decompose(A: any, ...) (A is a matrix_t)
6. Misc / lower-value
src/cache/cache.ts:9,47 — allocate(capacity: any, ...) (should be number)
src/imgproc/imgproc.ts:1179 — skindetector(src: { ...; data: any[] })
src/yape/yape_utils.ts:130 — dirs: any[] | Int32Array
Proposed approach
- Add a shared
export type TypedArray = Uint8Array | Int32Array | Float32Array | Float64Array; (e.g. in src/data_type/ or a small src/types.ts) and replace group 1.
- Replace group 2 with the existing
_pool_node_t type.
- Define and export a
MotionKernel interface; type groups 3–5 against it / matrix_t / point_t[].
- Mop up group 6 with the obvious primitive/real types.
Incremental is fine — one module (or one group) per commit. The parity suite (npm test, 63 tests) must stay green at each step since several of these are on hot numeric paths.
Impact
Low — no runtime behavior change; purely type-safety / DX. But it's cheap, self-contained, and removes a class of latent bugs the compiler currently can't catch. Aligns with the AGENTS.md convention: "Prefer real types over any in new code."
Non-goals
- Not enabling
strictNullChecks (separate, larger effort).
- Not touching generated
types/**/*.d.ts.
- No algorithm/numeric changes — types only.
Summary
The
.tssource still contains ~25 uses ofany(across ~9 modules). Most map to a small set of real shapes — introducing a few shared type aliases/interfaces would eliminate the majority and improve type safety, editor autocomplete and refactor safety.Environment
src/**/*.ts(excluding generatedtypes/**/*.d.ts)dev)tsconfigrunsstrict: truebutstrictNullChecks: falseandnoImplicitAny: true— so these are all explicitanys, not inferred ones.Actual state (inventory)
Grouped by the underlying real type, most-impactful first:
1. Typed-array payloads → a shared
TypedArrayaliasThe recurring one.
matrix_t.data,pyramid_t.data, pool buffers etc. are always one ofUint8Array | Int32Array | Float32Array | Float64Array.src/matrix_t/matrix_t.ts:19,63—data: any(interface + class)src/matrix_t/matrix_t.ts:25,27—copy_to(other: any),resize(..., ch: any)src/pyramid_t/pyramid_t.ts:17,59—data: any,b: any = this.data[0]src/node_utils/data_t.ts:44—buffer?: anysrc/node_utils/_pool_node_t.ts:22—buffer: anysrc/imgproc/imgproc.ts:698—dst_tilted: any[]src/optical_flow_lk/optical_flow_lk.ts:18—scharr_deriv: any2. Cache pool node →
_pool_node_tsrc/cache/cache.ts:13,85—put_buffer(node: any)(interface + impl); the node is a_pool_node_tsrc/node_utils/_pool_node_t.ts:16—next: any(self-referential_pool_node_t)3. Motion-model kernel → a
MotionKernelinterfacemotion_estimator.ransac/lmedstakekernel: any; the real contract is{ run(from, to, model, count): number; error(...): void; check_subset(...): boolean }, implemented byaffine2d/homography2d.src/motion_estimator/motion_estimator.ts:137,250—kernel: any4. Point-subset scratch arrays →
point_t[]src/motion_estimator/motion_estimator.ts:156,157,270,271—subset0/1: any = []5. matrix_t args typed loosely →
matrix_tsrc/linalg/linalg.ts:605—svd_decompose(A: any, ...)(A is amatrix_t)6. Misc / lower-value
src/cache/cache.ts:9,47—allocate(capacity: any, ...)(should benumber)src/imgproc/imgproc.ts:1179—skindetector(src: { ...; data: any[] })src/yape/yape_utils.ts:130—dirs: any[] | Int32ArrayProposed approach
export type TypedArray = Uint8Array | Int32Array | Float32Array | Float64Array;(e.g. insrc/data_type/or a smallsrc/types.ts) and replace group 1._pool_node_ttype.MotionKernelinterface; type groups 3–5 against it /matrix_t/point_t[].Incremental is fine — one module (or one group) per commit. The parity suite (
npm test, 63 tests) must stay green at each step since several of these are on hot numeric paths.Impact
Low — no runtime behavior change; purely type-safety / DX. But it's cheap, self-contained, and removes a class of latent bugs the compiler currently can't catch. Aligns with the
AGENTS.mdconvention: "Prefer real types overanyin new code."Non-goals
strictNullChecks(separate, larger effort).types/**/*.d.ts.