Add type definition for koa-json-error (#10951)

* Add type definition for koa-json-error

* Consist with import statement
This commit is contained in:
Mudkip
2016-09-06 23:06:12 +09:00
committed by Masahiro Wakame
parent 8ca65ab187
commit fdbf262aa9
2 changed files with 49 additions and 0 deletions
+13
View File
@@ -0,0 +1,13 @@
/// <reference path="../koa/koa.d.ts" />
/// <reference path="koa-json-error.d.ts" />
/// <reference path="../lodash/lodash.d.ts" />
import * as Koa from "koa";
import * as error from "koa-json-error";
import { assign } from "lodash";
const app = new Koa();
app.use(error({
preFormat: err => assign({}, err)
}));
+36
View File
@@ -0,0 +1,36 @@
// Type definitions for koa-json-error v3.x
// Project: https://github.com/koajs/json-error
// Definitions by: Mudkip <https://github.com/mudkipme>
// Definitions: https://github.com/mudkipme/DefinitelyTyped
/// <reference path="../koa/koa.d.ts" />
declare module "koa-json-error" {
import * as Koa from "koa";
interface JSONErrorOptions {
/**
* Perform some task before calling `options.format`. Must be a function with the original err as its only argument.
*/
preFormat?: { (err: Error): any };
/**
* Runs inmediatly after `options.preFormat`. It receives two arguments: the original `err` and the output of `options.preFormat`. It should `return` a newly formatted error.
*/
format?: { (err: Error, obj: any): any };
/**
* Runs inmediatly after `options.format`. It receives two arguments: the original `err` and the output of `options.format`. It should `return` a newly formatted error.
*/
postFormat?: { (err: Error, obj: any): any };
}
/**
* Error handler for pure Koa 2.0.0+ JSON apps
*/
function jsonError(options?: JSONErrorOptions) : { (ctx: Koa.Context, next?: () => any): any };
namespace jsonError {}
export = jsonError;
}