Device class / typings are not exported
MindfulMinun opened this issue · comments
It's impossible to declare TypeScript typings for a function that takes in a USB device as an argument, since it is not exported:
import usb from "https://deno.land/x/webusb@0.4.0/mod.ts"
const devices = await usb.getDevices()
initDevice(devices[0])
async function initDevice(device: /* what goes here? */) {
await device.open()
console.log(`${device.productName} - ${device.serialNumber}`);
}
Likewise, it's impossible to tell if an object is a USB device via an instanceof
check, since the class isn't exported either.
Could you consider exporting the types/classes?
types and classes should be exported in 0.4.1
. The module might not work well with TypeScript though, as I use --no-check
for most of the things. PRs fixing type issues are welcome.
Gotcha 👍 In case anyone else stumbles upon this issue, one workaround is to use external typings. This depends on the implementation being aligned with the spec
// @deno-types="https://esm.sh/@types/w3c-web-usb/index.d.ts"
import "https://deno.land/x/webusb@0.4.0/mod.ts"
// Accessible via `navigator.usb`