Add express-async-wrap (#35030)

* adds types for express-async-wrap

* Adds express-async-wrap properly

* Adds typescript version to express-async-wrap

* removes unnecessary generics

* removes unnecessary comment

* fix: now uses export default
This commit is contained in:
Rémy Oudemans 2019-05-02 02:21:57 +02:00 committed by Pranav Senthilnathan
parent 1e697cb6e6
commit a807e4e416
4 changed files with 59 additions and 0 deletions

View File

@ -0,0 +1,17 @@
import asyncWrap from 'express-async-wrap';
import express = require('express');
const app = express();
const promise = new Promise(resolve => {
setTimeout(() => {
resolve("Success");
}, 250);
});
const asyncHandler = async (_: express.Request, res: express.Response) => {
await promise;
res.send('promise awaited');
};
app.get('/', asyncWrap(asyncHandler));

18
types/express-async-wrap/index.d.ts vendored Normal file
View File

@ -0,0 +1,18 @@
// Type definitions for express-async-wrap 1.0
// Project: https://github.com/Greenfields/express-async-wrap#readme
// Definitions by: Remy Oudemans <https://github.com/remyoudemans>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.7
import { NextFunction } from 'connect';
import { Response, RequestHandler, ErrorRequestHandler, Request } from 'express-serve-static-core';
declare function asyncWrap(
handler: (req: Request, res: Response, next: NextFunction) => Promise<void>
): RequestHandler;
declare function asyncWrap(
handler: (err: any, req: Request, res: Response, next: NextFunction) => Promise<void>,
): ErrorRequestHandler;
export default asyncWrap;

View File

@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"express-async-wrap-tests.ts"
]
}

View File

@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }