keichi / binary-parser

A blazing-fast declarative parser builder for binary data
MIT License
857 stars 134 forks source link

fix test: specify array type #214

Closed wpyoga closed 1 year ago

wpyoga commented 1 year ago

In test/primitive_parser.ts:125

    bytes.push(parseInt(s.slice(i, i + 8), 2));

There is an error if we open the file in VS Code:

Argument of type 'number' is not assignable to parameter of type 'never'.ts(2345)

This is because on line 120:

const bytes = [];

The type of bytes is inferred as never[]. This patch solves the problem by explicitly initializing bytes to an empty number array.

keichi commented 1 year ago

Thanks for pointing this out. Do you know how we can reproduce this without VS Code? We should catch this kind of error in the CI if possible. I ran tsc 4.6.4 with the --strict flag on this file but didn't get any error.

wpyoga commented 1 year ago

Unfortunately I haven't been able to reproduce this without VS Code. I have tried eslint-typescript and the now-deprecated tslint, but haven't been able to get it to show this error. Someone more knowledgeable should step in.

Running eslint does show quite a large number of other errors though...

$ npx eslint .

...

✖ 107 problems (38 errors, 69 warnings)
  2 errors and 0 warnings potentially fixable with the `--fix` option.
keichi commented 1 year ago

Ok, thanks for looking into it. I will open another issue to address the eslint warnings.