@@ -15,15 +15,18 @@ import {
1515 DeviceError ,
1616 FlashDataError ,
1717 FlashDataSource ,
18- FlashEvent ,
1918 FlashOptions ,
20- SerialDataEvent ,
21- SerialErrorEvent ,
22- SerialResetEvent ,
2319} from "./device.js" ;
2420import { TypedEventTarget } from "./events.js" ;
2521import { Logging , NullLogging } from "./logging.js" ;
2622import { PromiseQueue } from "./promise-queue.js" ;
23+ import {
24+ FlashEvent ,
25+ SerialConnectionEventMap ,
26+ SerialDataEvent ,
27+ SerialErrorEvent ,
28+ SerialResetEvent ,
29+ } from "./serial-events.js" ;
2730import { DAPWrapper } from "./usb-device-wrapper.js" ;
2831import { PartialFlashing } from "./usb-partial-flashing.js" ;
2932
@@ -41,7 +44,8 @@ export interface MicrobitWebUSBConnectionOptions {
4144 logging : Logging ;
4245}
4346
44- export interface MicrobitWebUSBConnection extends DeviceConnection {
47+ export interface MicrobitWebUSBConnection
48+ extends DeviceConnection < SerialConnectionEventMap > {
4549 /**
4650 * Gets micro:bit deviceId.
4751 *
@@ -80,13 +84,13 @@ export interface MicrobitWebUSBConnection extends DeviceConnection {
8084 */
8185export const createWebUSBConnection = (
8286 options ?: MicrobitWebUSBConnectionOptions ,
83- ) => new MicrobitWebUSBConnectionImpl ( options ) ;
87+ ) : MicrobitWebUSBConnection => new MicrobitWebUSBConnectionImpl ( options ) ;
8488
8589/**
8690 * A WebUSB connection to a micro:bit device.
8791 */
8892class MicrobitWebUSBConnectionImpl
89- extends TypedEventTarget < DeviceConnectionEventMap >
93+ extends TypedEventTarget < DeviceConnectionEventMap & SerialConnectionEventMap >
9094 implements MicrobitWebUSBConnection
9195{
9296 status : ConnectionStatus =
@@ -477,7 +481,7 @@ class MicrobitWebUSBConnectionImpl
477481 }
478482
479483 protected eventActivated ( type : string ) : void {
480- switch ( type as keyof DeviceConnectionEventMap ) {
484+ switch ( type as keyof SerialConnectionEventMap ) {
481485 case "serialdata" : {
482486 this . startSerialInternal ( ) ;
483487 break ;
@@ -486,7 +490,7 @@ class MicrobitWebUSBConnectionImpl
486490 }
487491
488492 protected async eventDeactivated ( type : string ) {
489- switch ( type as keyof DeviceConnectionEventMap ) {
493+ switch ( type as keyof SerialConnectionEventMap ) {
490494 case "serialdata" : {
491495 this . stopSerialInternal ( ) ;
492496 break ;
0 commit comments