Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add Deno.ServeDefaultExport type #24879

Merged
merged 4 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions cli/tsc/dts/lib.deno.ns.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6256,6 +6256,12 @@ declare namespace Deno {
info: ServeHandlerInfo,
) => Response | Promise<Response>;

export interface Serve {
fetch: (
request: Request,
) => Response | Promise<Response>;
}
bartlomieju marked this conversation as resolved.
Show resolved Hide resolved

/** Options which can be set when calling {@linkcode Deno.serve}.
*
* @category HTTP Server
Expand Down
6 changes: 6 additions & 0 deletions tests/specs/serve/type_check/__test__.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"args": "serve --check --port 12345 main.ts",
"output": "main.out",
"tempDir": true,
"exitCode": 1
}
5 changes: 5 additions & 0 deletions tests/specs/serve/type_check/main.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Check [WILDCARD]
error: TS2353 [ERROR]: Object literal may only specify known properties, and 'bad' does not exist in type 'Serve'.
bad() {
~~~
at [WILDCARD]main.ts:2:3
4 changes: 4 additions & 0 deletions tests/specs/serve/type_check/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export default {
bad() {
},
} satisfies Deno.Serve;
6 changes: 6 additions & 0 deletions tests/specs/serve/type_check2/__test__.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"args": "serve --check --port 12345 main.ts",
"output": "main.out",
"tempDir": true,
"exitCode": 1
}
5 changes: 5 additions & 0 deletions tests/specs/serve/type_check2/main.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Check [WILDCARD]
error: TS2339 [ERROR]: Property 'doesnt_exist' does not exist on type 'Request'.
console.log(request.doesnt_exist);
~~~~~~~~~~~~
at [WILDCARD]main.ts:3:25
6 changes: 6 additions & 0 deletions tests/specs/serve/type_check2/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export default {
fetch(request) {
console.log(request.doesnt_exist);
return new Response("Hello world!");
},
} satisfies Deno.Serve;
Loading