Skip to content

Commit 7eb661e

Browse files
authored
🤖 Merge PR DefinitelyTyped#73346 Update @types/koa to match koa version 3 by @AaronMoat
1 parent 86d5e1d commit 7eb661e

3 files changed

Lines changed: 27 additions & 9 deletions

File tree

types/koa/index.d.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import * as compose from "koa-compose";
2323
import { ListenOptions, Socket } from "net";
2424
import { ParsedUrlQuery } from "querystring";
2525
import * as url from "url";
26+
import type httpErrors = require("http-errors");
2627

2728
declare interface ContextDelegatedRequest {
2829
/**
@@ -324,6 +325,18 @@ declare interface ContextDelegatedResponse {
324325
*/
325326
vary(field: string | string[]): void;
326327

328+
/**
329+
* Perform a special-cased "back" to provide Referrer support.
330+
* When Referrer is not present, `alt` or "/" is used.
331+
*
332+
* Examples:
333+
*
334+
* ctx.back()
335+
* ctx.back('/index.html')
336+
*/
337+
338+
back(alt?: string): void;
339+
327340
/**
328341
* Perform a 302 redirect to `url`.
329342
*
@@ -333,12 +346,10 @@ declare interface ContextDelegatedResponse {
333346
*
334347
* Examples:
335348
*
336-
* this.redirect('back');
337-
* this.redirect('back', '/index.html');
338349
* this.redirect('/login');
339350
* this.redirect('http://google.com');
340351
*/
341-
redirect(url: string, alt?: string): void;
352+
redirect(url: string): void;
342353

343354
/**
344355
* Set Content-Disposition to "attachment" to signal the client to prompt for download.
@@ -683,9 +694,8 @@ declare namespace Application {
683694
*
684695
* See: https://github.com/jshttp/http-errors
685696
*/
686-
throw(message: string, code?: number, properties?: {}): never;
687-
throw(status: number): never;
688-
throw(...properties: Array<number | string | {}>): never;
697+
throw(status: number, ...args: httpErrors.UnknownError[]): never;
698+
throw(...args: httpErrors.UnknownError[]): never;
689699

690700
/**
691701
* Default error handling.

types/koa/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"private": true,
33
"name": "@types/koa",
4-
"version": "2.15.9999",
4+
"version": "3.0.9999",
55
"projects": [
66
"http://koajs.com"
77
],
@@ -10,7 +10,7 @@
1010
"@types/content-disposition": "*",
1111
"@types/cookies": "*",
1212
"@types/http-assert": "*",
13-
"@types/http-errors": "*",
13+
"@types/http-errors": "^2",
1414
"@types/keygrip": "*",
1515
"@types/koa-compose": "*",
1616
"@types/node": "*"

types/koa/test/index.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,15 @@ app.context.db = () => {};
2020

2121
app.use(async ctx => {
2222
if (ctx.errors) {
23-
ctx.throw(ctx.errors[0], 400);
23+
ctx.throw(400, ctx.errors[0]);
24+
ctx.throw(400);
25+
ctx.throw(400, "name required");
26+
ctx.throw(400, "name required", { user: { id: 7 } });
27+
ctx.throw(403);
28+
ctx.throw(400, "name required");
29+
ctx.throw("something exploded");
30+
ctx.throw(new Error("invalid"));
31+
ctx.throw(400, new Error("invalid"));
2432
}
2533
});
2634

0 commit comments

Comments
 (0)