Skip to content

Commit fd5c256

Browse files
authored
refactor(types): improve type definitions and organization (#148)
1 parent 6971782 commit fd5c256

2 files changed

Lines changed: 35 additions & 31 deletions

File tree

src/server.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { WebsocketServer } from './servers/WebsocketServer';
2121
import type {
2222
AddressInfo,
2323
BasicApplication,
24+
BasicServer,
2425
ClientConfiguration,
2526
ClientConnection,
2627
Compiler,
@@ -81,7 +82,7 @@ const require = createRequire(import.meta.url);
8182

8283
export interface Configuration<
8384
A extends BasicApplication = ConnectApplication,
84-
S extends HTTPServer = HTTPServer,
85+
S extends BasicServer = HTTPServer,
8586
> {
8687
ipc?: boolean | string;
8788
host?: Host;
@@ -190,7 +191,7 @@ function isMultiCompiler(
190191

191192
class Server<
192193
A extends BasicApplication = ConnectApplication,
193-
S extends import('http').Server = HTTPServer,
194+
S extends BasicServer = HTTPServer,
194195
> {
195196
compiler: Compiler | MultiCompiler;
196197
logger: ReturnType<Compiler['getInfrastructureLogger']>;

src/types.ts

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,42 +3,52 @@ import type {
33
IncomingMessage,
44
ServerResponse,
55
} from 'node:http';
6-
export type { HTTPServer, IncomingMessage };
7-
export type { Socket } from 'node:net';
8-
export type { AddressInfo } from 'node:net';
9-
export type { NetworkInterfaceInfo } from 'node:os';
10-
export type {
11-
Compiler,
12-
DevServer,
13-
MultiCompiler,
14-
MultiStats,
15-
Stats,
16-
StatsCompilation,
17-
StatsOptions,
18-
} from '@rspack/core';
6+
import type { ServerOptions } from 'node:https';
197
import type { FSWatcher, WatchOptions } from 'chokidar';
20-
export type { FSWatcher, WatchOptions };
8+
import type { Options as ConnectHistoryApiFallbackOptions } from 'connect-history-api-fallback';
219
import type {
2210
Server as ConnectApplication,
2311
IncomingMessage as ConnectIncomingMessage,
2412
} from 'connect-next';
25-
export type { ConnectApplication };
26-
import type { Options as ConnectHistoryApiFallbackOptions } from 'connect-history-api-fallback';
27-
export type { ConnectHistoryApiFallbackOptions };
2813
import type {
2914
Options as HttpProxyMiddlewareOptions,
3015
Filter as HttpProxyMiddlewareOptionsFilter,
3116
RequestHandler,
3217
} from 'http-proxy-middleware';
33-
export type { RequestHandler };
34-
export type { IPv6 } from 'ipaddr.js';
3518
import type { Options as ServeIndexOptions } from 'serve-index';
36-
export type { ServeIndexOptions };
3719
import type { ServeStaticOptions } from 'serve-static';
3820

21+
export type {
22+
FSWatcher,
23+
WatchOptions,
24+
RequestHandler,
25+
ServeIndexOptions,
26+
BasicServer,
27+
HTTPServer,
28+
ServerOptions,
29+
IncomingMessage,
30+
ConnectApplication,
31+
ConnectHistoryApiFallbackOptions,
32+
};
33+
export type { IPv6 } from 'ipaddr.js';
34+
export type { Socket } from 'node:net';
35+
export type { AddressInfo } from 'node:net';
36+
export type { NetworkInterfaceInfo } from 'node:os';
37+
export type {
38+
Compiler,
39+
DevServer,
40+
MultiCompiler,
41+
MultiStats,
42+
Stats,
43+
StatsCompilation,
44+
StatsOptions,
45+
} from '@rspack/core';
46+
3947
// biome-ignore lint/suspicious/noExplicitAny: expected any
4048
export type EXPECTED_ANY = any;
4149

50+
type BasicServer = import('node:net').Server | import('node:tls').Server;
51+
4252
/** https://github.com/microsoft/TypeScript/issues/29729 */
4353
export type LiteralUnion<T extends U, U> = T | (U & Record<never, never>);
4454

@@ -63,8 +73,6 @@ export type HandleFunction =
6373
| NextHandleFunction
6474
| ErrorHandleFunction;
6575

66-
export type ServerOptions = import('https').ServerOptions;
67-
6876
// type-level helpers, inferred as util types
6977
export type Request<T extends BasicApplication = ConnectApplication> =
7078
T extends ConnectApplication ? ConnectIncomingMessage : IncomingMessage;
@@ -116,16 +124,13 @@ export interface NormalizedStatic {
116124
watch: false | WatchOptions;
117125
}
118126

119-
export type ServerType<
120-
A extends BasicApplication = ConnectApplication,
121-
S extends import('http').Server = import('http').Server,
122-
> =
127+
export type ServerType<A extends BasicApplication, S extends BasicServer> =
123128
| LiteralUnion<'http' | 'https' | 'http2', string>
124129
| ((serverOptions: ServerOptions, application: A) => S);
125130

126131
export interface ServerConfiguration<
127132
A extends BasicApplication = ConnectApplication,
128-
S extends import('http').Server = import('http').Server,
133+
S extends BasicServer = HTTPServer,
129134
> {
130135
type?: ServerType<A, S>;
131136
options?: ServerOptions;
@@ -215,8 +220,6 @@ export interface MiddlewareObject {
215220

216221
export type Middleware = MiddlewareObject | MiddlewareHandler;
217222

218-
export type BasicServer = import('net').Server | import('tls').Server;
219-
220223
export type OverlayMessageOptions = boolean | ((error: Error) => void);
221224

222225
// TypeScript overloads for connect-like use

0 commit comments

Comments
 (0)