Skip to content

Commit 596493e

Browse files
authored
🤖 Merge PR DefinitelyTyped#73568 w3c-web-usb: fix nullable types by @dlech
1 parent 38f95e8 commit 596493e

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

types/w3c-web-usb/index.d.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ interface USBConnectionEventInit extends EventInit {
3939

4040
declare class USBConfiguration {
4141
readonly configurationValue: number;
42-
readonly configurationName?: string | undefined;
42+
readonly configurationName: string | null;
4343
readonly interfaces: USBInterface[];
4444
}
4545

@@ -57,7 +57,7 @@ declare class USBAlternateInterface {
5757
readonly interfaceClass: number;
5858
readonly interfaceSubclass: number;
5959
readonly interfaceProtocol: number;
60-
readonly interfaceName?: string | undefined;
60+
readonly interfaceName: string | null;
6161
readonly endpoints: USBEndpoint[];
6262
}
6363

@@ -140,10 +140,10 @@ declare class USBDevice {
140140
readonly deviceVersionMajor: number;
141141
readonly deviceVersionMinor: number;
142142
readonly deviceVersionSubminor: number;
143-
readonly manufacturerName?: string | undefined;
144-
readonly productName?: string | undefined;
145-
readonly serialNumber?: string | undefined;
146-
readonly configuration?: USBConfiguration | undefined;
143+
readonly manufacturerName: string | null;
144+
readonly productName: string | null;
145+
readonly serialNumber: string | null;
146+
readonly configuration: USBConfiguration | null;
147147
readonly configurations: USBConfiguration[];
148148
readonly opened: boolean;
149149
open(): Promise<void>;

types/w3c-web-usb/w3c-web-usb-tests.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,30 @@ async function handleConnectedDevice(device: USBDevice) {
8787
}
8888
}
8989
}
90+
91+
function testNullVsUndefined(device: USBDevice) {
92+
// There are certain properties that are nullable, meaning they return null
93+
// rather than undefined. These constructs test that this is the case.
94+
95+
if (device.manufacturerName !== null) {
96+
device.manufacturerName.length;
97+
}
98+
99+
if (device.productName !== null) {
100+
device.productName.length;
101+
}
102+
103+
if (device.serialNumber !== null) {
104+
device.serialNumber.length;
105+
}
106+
107+
if (device.configuration !== null) {
108+
if (device.configuration.configurationName !== null) {
109+
device.configuration.configurationName.length;
110+
}
111+
112+
if (device.configuration.interfaces[0].alternate.interfaceName !== null) {
113+
device.configuration.interfaces[0].alternate.interfaceName.length;
114+
}
115+
}
116+
}

0 commit comments

Comments
 (0)