From 4f481cd0838868a4ed35fe238e64bd4fe997d8aa Mon Sep 17 00:00:00 2001 From: Malcolm Kee Date: Wed, 12 Apr 2023 20:41:42 +1000 Subject: [PATCH] fix: overlay filter type definition --- client-src/index.js | 6 +-- client-src/overlay.js | 2 +- lib/Server.js | 2 +- types/lib/Server.d.ts | 103 ++++++++++++++++++++++++++++++++++++------ 4 files changed, 95 insertions(+), 18 deletions(-) diff --git a/client-src/index.js b/client-src/index.js index d5fdd6f80c..3a948884b5 100644 --- a/client-src/index.js +++ b/client-src/index.js @@ -12,9 +12,9 @@ import createSocketURL from "./utils/createSocketURL.js"; /** * @typedef {Object} OverlayOptions - * @property {boolean | (message: unknown) => boolean} [warnings] - * @property {boolean | (message: unknown) => boolean} [errors] - * @property {boolean | (message: unknown) => boolean} [runtimeErrors] + * @property {boolean | (error: Error) => boolean} [warnings] + * @property {boolean | (error: Error) => boolean} [errors] + * @property {boolean | (error: Error) => boolean} [runtimeErrors] * @property {string} [trustedTypesPolicyName] */ diff --git a/client-src/overlay.js b/client-src/overlay.js index b94b95a06a..210b4996d1 100644 --- a/client-src/overlay.js +++ b/client-src/overlay.js @@ -78,7 +78,7 @@ function formatProblem(type, item) { /** * @typedef {Object} CreateOverlayOptions * @property {string | null} trustedTypesPolicyName - * @property {boolean | (message: unknown) => void} [catchRuntimeError] + * @property {boolean | (error: Error) => void} [catchRuntimeError] */ /** diff --git a/lib/Server.js b/lib/Server.js index 320932c242..c09eecb4ff 100644 --- a/lib/Server.js +++ b/lib/Server.js @@ -157,7 +157,7 @@ const schema = require("./options.json"); */ /** - * @typedef {boolean | ((error: unknown) => void)} OverlayMessageOptions + * @typedef {boolean | ((error: Error) => void)} OverlayMessageOptions */ /** diff --git a/types/lib/Server.d.ts b/types/lib/Server.d.ts index e0ebce31d0..fb057c09ac 100644 --- a/types/lib/Server.d.ts +++ b/types/lib/Server.d.ts @@ -136,7 +136,7 @@ declare class Server { * @property {string} [username] */ /** - * @typedef {boolean | ((error: unknown) => void)} OverlayMessageOptions + * @typedef {boolean | ((error: Error) => void)} OverlayMessageOptions */ /** * @typedef {Object} ClientConfiguration @@ -316,7 +316,7 @@ declare class Server { * @property {string} [username] */ /** - * @typedef {boolean | ((error: unknown) => void)} OverlayMessageOptions + * @typedef {boolean | ((error: Error) => void)} OverlayMessageOptions */ /** * @typedef {Object} ClientConfiguration @@ -445,7 +445,7 @@ declare class Server { * @property {string} [username] */ /** - * @typedef {boolean | ((error: unknown) => void)} OverlayMessageOptions + * @typedef {boolean | ((error: Error) => void)} OverlayMessageOptions */ /** * @typedef {Object} ClientConfiguration @@ -516,6 +516,41 @@ declare class Server { type: string; multiple: boolean; description: string; + /** + * @typedef {Array<{ key: string; value: string }> | Record} Headers + */ + /** + * @typedef {{ name?: string, path?: string, middleware: ExpressRequestHandler | ExpressErrorRequestHandler } | ExpressRequestHandler | ExpressErrorRequestHandler} Middleware + */ + /** + * @typedef {Object} Configuration + * @property {boolean | string} [ipc] + * @property {Host} [host] + * @property {Port} [port] + * @property {boolean | "only"} [hot] + * @property {boolean} [liveReload] + * @property {DevMiddlewareOptions} [devMiddleware] + * @property {boolean} [compress] + * @property {boolean} [magicHtml] + * @property {"auto" | "all" | string | string[]} [allowedHosts] + * @property {boolean | ConnectHistoryApiFallbackOptions} [historyApiFallback] + * @property {boolean | Record | BonjourOptions} [bonjour] + * @property {string | string[] | WatchFiles | Array} [watchFiles] + * @property {boolean | string | Static | Array} [static] + * @property {boolean | ServerOptions} [https] + * @property {boolean} [http2] + * @property {"http" | "https" | "spdy" | string | ServerConfiguration} [server] + * @property {boolean | "sockjs" | "ws" | string | WebSocketServerConfiguration} [webSocketServer] + * @property {ProxyConfigMap | ProxyConfigArrayItem | ProxyConfigArray} [proxy] + * @property {boolean | string | Open | Array} [open] + * @property {boolean} [setupExitSignals] + * @property {boolean | ClientConfiguration} [client] + * @property {Headers | ((req: Request, res: Response, context: DevMiddlewareContext) => Headers)} [headers] + * @property {(devServer: Server) => void} [onAfterSetupMiddleware] + * @property {(devServer: Server) => void} [onBeforeSetupMiddleware] + * @property {(devServer: Server) => void} [onListening] + * @property {(middlewares: Middleware[], devServer: Server) => Middleware[]} [setupMiddlewares] + */ negatedDescription: string; path: string; } @@ -623,10 +658,6 @@ declare class Server { )[]; description: string; multiple: boolean; - /** - * @param {string} URL - * @returns {boolean} - */ simpleType: string; }; "client-web-socket-url-username": { @@ -684,6 +715,11 @@ declare class Server { simpleType: string; multiple: boolean; }; + /** + * @param {Port} port + * @param {string} host + * @returns {Promise} + */ hot: { configs: ( | { @@ -785,7 +821,6 @@ declare class Server { multiple: boolean; }; "https-cert-reset": { - /** @type {string} */ configs: { description: string; multiple: boolean; @@ -981,6 +1016,10 @@ declare class Server { description: string; simpleType: string; multiple: boolean; + /** + * @private + * @returns {Promise} + */ }; "open-reset": { configs: { @@ -1225,7 +1264,7 @@ declare class Server { "static-directory": { configs: { type: string; - /** @type {Array} */ multiple: boolean; + multiple: boolean; description: string; path: string; }[]; @@ -1556,7 +1595,7 @@ declare class Server { * @property {string} [username] */ /** - * @typedef {boolean | ((error: unknown) => void)} OverlayMessageOptions + * @typedef {boolean | ((error: Error) => void)} OverlayMessageOptions */ /** * @typedef {Object} ClientConfiguration @@ -1716,7 +1755,7 @@ declare class Server { * @property {string} [username] */ /** - * @typedef {boolean | ((error: unknown) => void)} OverlayMessageOptions + * @typedef {boolean | ((error: Error) => void)} OverlayMessageOptions */ /** * @typedef {Object} ClientConfiguration @@ -1819,6 +1858,35 @@ declare class Server { description: string; link: string; }; + /** + * @typedef {Object} Configuration + * @property {boolean | string} [ipc] + * @property {Host} [host] + * @property {Port} [port] + * @property {boolean | "only"} [hot] + * @property {boolean} [liveReload] + * @property {DevMiddlewareOptions} [devMiddleware] + * @property {boolean} [compress] + * @property {boolean} [magicHtml] + * @property {"auto" | "all" | string | string[]} [allowedHosts] + * @property {boolean | ConnectHistoryApiFallbackOptions} [historyApiFallback] + * @property {boolean | Record | BonjourOptions} [bonjour] + * @property {string | string[] | WatchFiles | Array} [watchFiles] + * @property {boolean | string | Static | Array} [static] + * @property {boolean | ServerOptions} [https] + * @property {boolean} [http2] + * @property {"http" | "https" | "spdy" | string | ServerConfiguration} [server] + * @property {boolean | "sockjs" | "ws" | string | WebSocketServerConfiguration} [webSocketServer] + * @property {ProxyConfigMap | ProxyConfigArrayItem | ProxyConfigArray} [proxy] + * @property {boolean | string | Open | Array} [open] + * @property {boolean} [setupExitSignals] + * @property {boolean | ClientConfiguration} [client] + * @property {Headers | ((req: Request, res: Response, context: DevMiddlewareContext) => Headers)} [headers] + * @property {(devServer: Server) => void} [onAfterSetupMiddleware] + * @property {(devServer: Server) => void} [onBeforeSetupMiddleware] + * @property {(devServer: Server) => void} [onListening] + * @property {(middlewares: Middleware[], devServer: Server) => Middleware[]} [setupMiddlewares] + */ ClientWebSocketTransportEnum: { enum: string[]; }; @@ -1940,6 +2008,10 @@ declare class Server { ca: { anyOf: ( | { + /** + * @param {string} URL + * @returns {boolean} + */ type: string; items: { anyOf: ( @@ -2158,6 +2230,7 @@ declare class Server { }; }; cli: { + /** @type {ClientConfiguration} */ exclude: boolean; }; }; @@ -2511,6 +2584,10 @@ declare class Server { type?: undefined; } )[]; + /** + * @private + * @returns {Promise} + */ }; instanceof?: undefined; } @@ -2901,7 +2978,7 @@ declare class Server { } )[]; cli: { - description: string; + description: string /** @type {Array} */; } /** @type {Array} */; }; WebSocketServerFunction: { @@ -3592,7 +3669,7 @@ type WebSocketURL = { protocol?: string | undefined; username?: string | undefined; }; -type OverlayMessageOptions = boolean | ((error: unknown) => void); +type OverlayMessageOptions = boolean | ((error: Error) => void); type ClientConfiguration = { logging?: "none" | "error" | "warn" | "info" | "log" | "verbose" | undefined; overlay?: