Skip to content

Commit 8edc14a

Browse files
committed
fix: ensure usbDevice.configuration is non-null before accessing interfaces
1 parent aa35d29 commit 8edc14a

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/usb/sagas.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,12 +179,16 @@ function* handleUsbConnectPybricks(hotPlugDevice?: USBDevice): Generator {
179179
}
180180
}
181181

182+
// usbDevice.configuration as non-null because we either just selected it or
183+
// Now we know that usbDevice.configuration can never be null, as firware and
184+
// a "1" configuration exists
185+
182186
assert(
183-
usbDevice.configuration.interfaces.length > 0,
187+
usbDevice.configuration!.interfaces.length > 0,
184188
'USB device has no interfaces',
185189
);
186190

187-
const iface = usbDevice.configuration.interfaces.find(
191+
const iface = usbDevice.configuration!.interfaces.find(
188192
(iface) =>
189193
iface.alternate.interfaceClass === pybricksUsbClass &&
190194
iface.alternate.interfaceSubclass === pybricksUsbSubclass &&

0 commit comments

Comments
 (0)