Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions types/w3c-web-usb/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
}

Expand All @@ -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[];
}

Expand Down Expand Up @@ -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<void>;
Expand Down
27 changes: 27 additions & 0 deletions types/w3c-web-usb/w3c-web-usb-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}