Skip to content

Commit 6b05dfb

Browse files
authored
🤖 Merge PR DefinitelyTyped#74242 [w3c-direct-sockets] Mark members of OpenInfo dictionaries as required. by @paulinagacek
1 parent 81b3367 commit 6b05dfb

File tree

2 files changed

+39
-13
lines changed

2 files changed

+39
-13
lines changed

‎types/w3c-direct-sockets/index.d.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ export interface TCPServerSocketOptions {
7171
}
7272

7373
export interface SocketOpenInfo {
74-
readable?: ReadableStream;
75-
writable?: WritableStream;
74+
readable: ReadableStream;
75+
writable: WritableStream;
7676
remoteAddress?: string;
7777
remotePort?: number;
7878
localAddress?: string;
@@ -86,7 +86,7 @@ export interface UDPSocketOpenInfo extends SocketOpenInfo {
8686
}
8787

8888
export interface TCPServerSocketOpenInfo {
89-
readable?: ReadableStream;
89+
readable: ReadableStream;
9090
localAddress?: string;
9191
localPort?: number;
9292
}

‎types/w3c-direct-sockets/w3c-direct-sockets-tests.ts‎

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ async function testDirectSockets() {
8989
// --------------------------------------------------------------------------------
9090
// TCPServerSocket
9191
// --------------------------------------------------------------------------------
92+
93+
// @ts-expect-error
94+
const invalidTcpServerOpenInfo: TCPServerSocketOpenInfo = {};
95+
9296
const tcpServerOptions: TCPServerSocketOptions = {
9397
localPort: 0,
9498
backlog: 5,
@@ -113,23 +117,45 @@ async function testDirectSockets() {
113117
// Open Info Structures
114118
// --------------------------------------------------------------------------------
115119

116-
const udpOpenInfo: UDPSocketOpenInfo = {};
120+
const udpOpenInfo: UDPSocketOpenInfo = {
121+
readable: {} as ReadableStream,
122+
writable: {} as WritableStream, // Only include if your d.ts actually requires this
123+
remoteAddress: "127.0.0.1",
124+
remotePort: 53,
125+
localAddress: "0.0.0.0",
126+
localPort: 4500,
127+
};
117128
// $ExpectType MulticastController | undefined
118129
udpOpenInfo.multicastController;
119-
// $ExpectType ReadableStream<any> | undefined
130+
131+
// $ExpectType ReadableStream<any>
120132
udpOpenInfo.readable;
121133

122-
const tcpOpenInfo: TCPSocketOpenInfo = {};
134+
// ============================================================================
135+
// TCPSocketOpenInfo (REQUIRED FIELDS TEST)
136+
// ============================================================================
137+
123138
// @ts-expect-error
124-
tcpOpenInfo.multicastController;
125-
// $ExpectType WritableStream<any> | undefined
126-
tcpOpenInfo.writable;
139+
const invalidTcpOpenInfo: TCPSocketOpenInfo = {};
140+
141+
const validTcpOpenInfo: TCPSocketOpenInfo = {
142+
readable: {} as ReadableStream,
143+
writable: {} as WritableStream,
144+
remoteAddress: "127.0.0.1",
145+
remotePort: 80,
146+
localAddress: "192.168.1.5",
147+
localPort: 3000,
148+
};
149+
150+
// $ExpectType ReadableStream<any>
151+
validTcpOpenInfo.readable;
152+
// $ExpectType WritableStream<any>
153+
validTcpOpenInfo.writable;
154+
// $ExpectType string | undefined
155+
validTcpOpenInfo.remoteAddress;
127156

128-
const tcpServerOpenInfo: TCPServerSocketOpenInfo = {};
129-
// $ExpectType ReadableStream<any> | undefined
130-
tcpServerOpenInfo.readable;
131157
// @ts-expect-error
132-
tcpServerOpenInfo.writable;
158+
validTcpOpenInfo.multicastController;
133159

134160
// --------------------------------------------------------------------------------
135161
// MulticastController

0 commit comments

Comments
 (0)