diff --git a/types/w3c-web-usb/index.d.ts b/types/w3c-web-usb/index.d.ts index b59810ce0fcaaf..00973d8e669ef1 100644 --- a/types/w3c-web-usb/index.d.ts +++ b/types/w3c-web-usb/index.d.ts @@ -39,7 +39,7 @@ interface USBConnectionEventInit extends EventInit { declare class USBConfiguration { readonly configurationValue: number; - readonly configurationName?: string | undefined; + readonly configurationName: string | null; readonly interfaces: USBInterface[]; } @@ -57,7 +57,7 @@ declare class USBAlternateInterface { readonly interfaceClass: number; readonly interfaceSubclass: number; readonly interfaceProtocol: number; - readonly interfaceName?: string | undefined; + readonly interfaceName: string | null; readonly endpoints: USBEndpoint[]; } @@ -140,10 +140,10 @@ declare class USBDevice { readonly deviceVersionMajor: number; readonly deviceVersionMinor: number; readonly deviceVersionSubminor: number; - readonly manufacturerName?: string | undefined; - readonly productName?: string | undefined; - readonly serialNumber?: string | undefined; - readonly configuration?: USBConfiguration | undefined; + readonly manufacturerName: string | null; + readonly productName: string | null; + readonly serialNumber: string | null; + readonly configuration: USBConfiguration | null; readonly configurations: USBConfiguration[]; readonly opened: boolean; open(): Promise; diff --git a/types/w3c-web-usb/w3c-web-usb-tests.ts b/types/w3c-web-usb/w3c-web-usb-tests.ts index 5683f86054e73f..c743324de039da 100644 --- a/types/w3c-web-usb/w3c-web-usb-tests.ts +++ b/types/w3c-web-usb/w3c-web-usb-tests.ts @@ -87,3 +87,30 @@ async function handleConnectedDevice(device: USBDevice) { } } } + +function testNullVsUndefined(device: USBDevice) { + // There are certain properties that are nullable, meaning they return null + // rather than undefined. These constructs test that this is the case. + + if (device.manufacturerName !== null) { + device.manufacturerName.length; + } + + if (device.productName !== null) { + device.productName.length; + } + + if (device.serialNumber !== null) { + device.serialNumber.length; + } + + if (device.configuration !== null) { + if (device.configuration.configurationName !== null) { + device.configuration.configurationName.length; + } + + if (device.configuration.interfaces[0].alternate.interfaceName !== null) { + device.configuration.interfaces[0].alternate.interfaceName.length; + } + } +}