I am currently working on creating a USB driver in TypeScript using the libusb library to adjust my keyboard lighting. However, I encountered an issue where I received a 'possibly undefined' error when trying to retrieve the interface number. The code is running on Windows, but it's identical to a tutorial I followed that was designed for Linux.
Below is the snippet of the code:
import * as usb from 'usb';
const VID = 0X0C45;
const PID = 0x672E;
const IN = 1;
const main = async () => {
const device = usb.findByIds(VID, PID);
console.log(device);
device?.open();
const deviceInterface = device?.interfaces[IN]; // Issue occurs here
console.log(deviceInterface);
}
main();
Any suggestions on how to address this problem?
It seems adding a "?" can resolve the issue, but the compiler throws an error saying ": expected".