espressif / esptool-js

Javascript implementation of flasher tool for Espressif chips, running in web browser using WebSerial.
https://espressif.github.io/esptool-js/
Apache License 2.0
288 stars 108 forks source link

Enable strict mode for TypeScript #70

Closed balloob closed 1 year ago

balloob commented 1 year ago

Maintenance issue. Now that we're using TypeScript, it would be great to enable strict: true in tsconfig.json. It currently generates a bunch of warnings that are potentially bugs.

❯ tsc
src/esploader.ts:30:7 - error TS2322: Type 'null' is not assignable to type 'ROM'.

30       return null;
         ~~~~~~~~~~~~

src/esploader.ts:100:5 - error TS2322: Type 'null' is not assignable to type 'ROM'.

100     this.chip = null;
        ~~~~~~~~~

src/esploader.ts:180:16 - error TS2345: Argument of type 'unknown' is not assignable to parameter of type 'string'.

180       this.log(e);
                   ~

src/esploader.ts:328:18 - error TS2345: Argument of type 'unknown' is not assignable to parameter of type 'string'.

328         this.log(e);
                     ~

src/esploader.ts:344:18 - error TS2345: Argument of type 'unknown' is not assignable to parameter of type 'string'.

344         this.log(error);
                     ~~~~~

src/esploader.ts:766:16 - error TS2345: Argument of type 'unknown' is not assignable to parameter of type 'string'.

766       this.log(e);
                   ~

src/esploader.ts:992:53 - error TS2454: Variable 'calcmd5' is used before being assigned.

992         if (new String(res).valueOf() != new String(calcmd5).valueOf()) {
                                                        ~~~~~~~

src/esploader.ts:993:36 - error TS2454: Variable 'calcmd5' is used before being assigned.

993           this.log("File  md5: " + calcmd5);
                                       ~~~~~~~

src/webserial.ts:130:20 - error TS2531: Object is possibly 'null'.

130     const reader = this.device.readable.getReader();
                       ~~~~~~~~~~~~~~~~~~~~

Found 9 errors in 2 files.

Errors  Files
     8  src/esploader.ts:30
     1  src/webserial.ts:130