From 3e1f98236f2a0d1db331caf0a246660fcd104deb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Mon, 5 Aug 2024 22:19:09 +0100 Subject: feat: Add Deno.ServeDefaultExport type (#24879) Closes https://github.com/denoland/deno/issues/23725 --- cli/tsc/dts/lib.deno.ns.d.ts | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'cli/tsc/dts/lib.deno.ns.d.ts') diff --git a/cli/tsc/dts/lib.deno.ns.d.ts b/cli/tsc/dts/lib.deno.ns.d.ts index cbf86eec6..084dc1b76 100644 --- a/cli/tsc/dts/lib.deno.ns.d.ts +++ b/cli/tsc/dts/lib.deno.ns.d.ts @@ -6256,6 +6256,35 @@ declare namespace Deno { info: ServeHandlerInfo, ) => Response | Promise; + /** Interface that module run with `deno serve` subcommand must conform to. + * + * To ensure your code is type-checked properly, make sure to add `satisfies Deno.ServeDefaultExport` + * to the `export default { ... }` like so: + * + * ```ts + * export default { + * fetch(req) { + * return new Response("Hello world"); + * } + * } satisfies Deno.ServeDefaultExport; + * ``` + * + * @category HTTP Server + */ + export interface ServeDefaultExport { + /** A handler for HTTP requests. Consumes a request and returns a response. + * + * If a handler throws, the server calling the handler will assume the impact + * of the error is isolated to the individual request. It will catch the error + * and if necessary will close the underlying connection. + * + * @category HTTP Server + */ + fetch: ( + request: Request, + ) => Response | Promise; + } + /** Options which can be set when calling {@linkcode Deno.serve}. * * @category HTTP Server -- cgit v1.2.3