Skip to content

fix: align TypeScript types with native bindings - #115

Merged
lukaszkurantdev merged 1 commit into
lukaszkurantdev:mainfrom
maxgalbu:fix/ts-types-match-native-bindings
Aug 3, 2026
Merged

fix: align TypeScript types with native bindings#115
lukaszkurantdev merged 1 commit into
lukaszkurantdev:mainfrom
maxgalbu:fix/ts-types-match-native-bindings

Conversation

@maxgalbu

Copy link
Copy Markdown
Contributor

Summary

Four places where the published TypeScript types disagree with the library's own native (C++/JSI) argument parsing. Each fix is verified against the repo's own native source on main; these were not runtime-tested on a device.

1. Mat.create — required params typed as optional (segfault)

  • Native: cpp/structures/mat/MatFactory.cpp:13-15 reads args[0].asNumber(), args[1].asNumber(), args[2].asNumber() unconditionally (the data argument is guarded by count > 3 at line 21, but rows/cols/type are not).
  • Current TS: static create(rows?: number, cols?: number, dataType?: DataTypes, data?: number[]) in src/objects/Objects.ts.
  • Symptom: the optional typing invites Mat.create() with fewer than 3 args, which reads non-existent JSI arguments and segfaults.
  • Fix: make rows, cols, dataType required; keep data? optional.

2. getPerspectiveTransform — wrong vector type

  • Native: cpp/FOCV_Function.cpp:1221-1222 reads args.asPoint2fVectorPtr(1) / asPoint2fVectorPtr(2) for src and dst.
  • Current TS: src/dst typed as PointVector in src/functions/ImageProcessing/ImageTransform.ts.
  • Symptom: passing a PointVector throws Argument is not a Point2fVector at runtime.
  • Fix: type src/dst as Point2fVector and update the type import.

3. Mat.saveToFile — missing params

  • Native: cpp/structures/mat/MatDelegate.cpp reads path = args[0] (string, line 100), format = args[1] (string, must be "jpeg" or "png", line 107), compression = args[2] (number 0..1, line 110).
  • Current TS: saveToFile(path: string): void in src/objects/Objects.ts.
  • Symptom: the type omits two required arguments, so type-checked calls pass only path and fail native validation.
  • Fix: saveToFile(path: string, format: 'jpeg' | 'png', compression: number): void.

4. saveToFile native arg-count guard is off by one

  • Native: cpp/structures/mat/MatDelegate.cpp:93 guards with if (count < 4) but the handler only reads args[0..2] (3 args).
  • Symptom: a correct 3-argument call throws saveToFile requires 3 arguments: path, format, compression.
  • Fix: change the guard to if (count < 3).

Verification

Verified against the repo's native source (not runtime-tested). yarn typecheck and yarn lint pass locally; the lefthook pre-commit hook (types, lint, commitlint) passed on commit.

Correct four places where the published TS types disagree with the
library's own native argument parsing, verified against the C++ source.

- Mat.create: make rows/cols/dataType required (native reads args[0..2]
  unconditionally in MatFactory.cpp; calling with no args segfaults).
- getPerspectiveTransform: type src/dst as Point2fVector (native reads
  asPoint2fVectorPtr in FOCV_Function.cpp; PointVector throws at runtime).
- Mat.saveToFile: type the format and compression params (native reads
  path/format/compression in MatDelegate.cpp).
- saveToFile native guard: change `count < 4` to `count < 3` so a correct
  3-argument call no longer throws (handler only reads args[0..2]).
@lukaszkurantdev
lukaszkurantdev merged commit 290a7a1 into lukaszkurantdev:main Aug 3, 2026
3 checks passed
@maxgalbu
maxgalbu deleted the fix/ts-types-match-native-bindings branch August 20, 2026 06:11
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.

2 participants