iwoplaza / typed-binary

Describe binary structures with full TypeScript support. Encode and decode into pure JavaScript objects.
MIT License
25 stars 1 forks source link

Linter complaints when using big endian IO #15

Closed UlrichEckhardt closed 1 month ago

UlrichEckhardt commented 1 month ago

Heya!

Following code is criticized by my linter:

const writer = new BufferWriter(buffer, { endianness: 'big' });
const reader = new BufferReader(buffer, { endianness: 'big' });

Its complaint is:

Argument of type '{ endianness: "big"; }' is not assignable to parameter of type 'BufferIOOptions'. Property 'byteOffset' is missing in type '{ endianness: "big"; }' but required in type 'BufferIOOptions'.ts(2345)

Without testing it extensively, this seems to resolve the issue:

diff --git a/src/io/bufferIOBase.ts b/src/io/bufferIOBase.ts
index 9da3e85..9e54a0a 100644
--- a/src/io/bufferIOBase.ts
+++ b/src/io/bufferIOBase.ts
@@ -5,11 +5,11 @@ export type BufferIOOptions = {
   /**
    * @default 0
    */
-  byteOffset: number;
+  byteOffset?: number;
   /**
    * @default 'system'
    */
-  endianness: Endianness | 'system';
+  endianness?: Endianness | 'system';
 };

Thanks for your effort!

Uli

iwoplaza commented 1 month ago

Thank you for the issue report! I will promptly look into it and add test coverage for this.

iwoplaza commented 1 month ago

@UlrichEckhardt Just made a PR that addresses this issue, let me know if the test cases cover the issues you had with the library. #17

iwoplaza commented 1 month ago

Fix released as part of version 4.0.1