fix strict mode errors

This commit is contained in:
Ivan Grokhotkov 2023-01-17 10:09:50 +08:00
parent 94c9bc8740
commit 9bbb76e016
No known key found for this signature in database
GPG Key ID: 1E050E141B280628
2 changed files with 10 additions and 10 deletions

View File

@ -3,7 +3,7 @@ import { deflate } from "pako";
import { Transport } from "./webserial"; import { Transport } from "./webserial";
import { ROM } from "./targets/rom"; import { ROM } from "./targets/rom";
async function magic2Chip(magic: number): Promise<ROM> { async function magic2Chip(magic: number): Promise<ROM | null> {
switch (magic) { switch (magic) {
case 0x00f01d83: { case 0x00f01d83: {
const { ESP32ROM } = await import("./targets/esp32"); const { ESP32ROM } = await import("./targets/esp32");
@ -86,7 +86,7 @@ export class ESPLoader {
USB_JTAG_SERIAL_PID = 0x1001; USB_JTAG_SERIAL_PID = 0x1001;
chip: ROM; chip!: ROM;
IS_STUB: boolean; IS_STUB: boolean;
FLASH_WRITE_SIZE: number; FLASH_WRITE_SIZE: number;
@ -98,7 +98,6 @@ export class ESPLoader {
private debugLogging = false, private debugLogging = false,
) { ) {
this.IS_STUB = false; this.IS_STUB = false;
this.chip = null;
this.FLASH_WRITE_SIZE = 0x4000; this.FLASH_WRITE_SIZE = 0x4000;
if (this.terminal) { if (this.terminal) {
this.terminal.clean(); this.terminal.clean();
@ -189,7 +188,7 @@ export class ESPLoader {
try { try {
await this.transport.rawRead(200); await this.transport.rawRead(200);
} catch (e) { } catch (e) {
this.error(e); this.error((e as Error).message);
} }
} }
@ -328,7 +327,7 @@ export class ESPLoader {
const res = await this.transport.read(1000); const res = await this.transport.read(1000);
i += res.length; i += res.length;
} catch (e) { } catch (e) {
this.debug(e); this.debug((e as Error).message);
if (e instanceof Error) { if (e instanceof Error) {
keepReading = false; keepReading = false;
break; break;
@ -344,7 +343,6 @@ export class ESPLoader {
this.debug(resp[0].toString()); this.debug(resp[0].toString());
return "success"; return "success";
} catch (error) { } catch (error) {
this.debug(error);
if (error instanceof Error) { if (error instanceof Error) {
if (esp32r0_delay) { if (esp32r0_delay) {
this.info("_", false); this.info("_", false);
@ -381,9 +379,11 @@ export class ESPLoader {
if (!detecting) { if (!detecting) {
const chip_magic_value = (await this.read_reg(0x40001000)) >>> 0; const chip_magic_value = (await this.read_reg(0x40001000)) >>> 0;
this.debug("Chip Magic " + chip_magic_value.toString(16)); this.debug("Chip Magic " + chip_magic_value.toString(16));
this.chip = await magic2Chip(chip_magic_value); const chip = await magic2Chip(chip_magic_value);
if (this.chip === null) { if (this.chip === null) {
throw new ESPError(`Unexpected CHIP magic value ${chip_magic_value}. Failed to autodetect chip type.`); throw new ESPError(`Unexpected CHIP magic value ${chip_magic_value}. Failed to autodetect chip type.`);
} else {
this.chip = chip as ROM;
} }
} }
} }
@ -768,7 +768,7 @@ export class ESPLoader {
try { try {
await this.transport.rawRead(500); await this.transport.rawRead(500);
} catch (e) { } catch (e) {
this.debug(e); this.debug((e as Error).message);
} }
} }
@ -912,7 +912,7 @@ export class ESPLoader {
continue; continue;
} }
image = this._update_image_flash_params(image, address, flash_size, flash_mode, flash_freq); image = this._update_image_flash_params(image, address, flash_size, flash_mode, flash_freq);
let calcmd5: string; let calcmd5: string | null = null;
if (calculateMD5Hash) { if (calculateMD5Hash) {
calcmd5 = calculateMD5Hash(image); calcmd5 = calculateMD5Hash(image);
this.debug("Image MD5 " + calcmd5); this.debug("Image MD5 " + calcmd5);

View File

@ -122,7 +122,7 @@ class Transport {
packet = this.left_over; packet = this.left_over;
this.left_over = new Uint8Array(0); this.left_over = new Uint8Array(0);
} }
if (typeof this.device.readable == "undefined") { if (this.device.readable == null) {
return this.left_over; return this.left_over;
} }