Allow typing Express body, params, query and cookies through generics (#20820)

* Allow typing express body, params, query and cookies through generics

* Increase minor version

* Add ts version comment

* Fix ts requirement comment typo

* Bump all ts version packages

* Bump Morgan package
This commit is contained in:
Alexandre
2017-10-24 01:23:31 +01:00
committed by Andy
parent 902ee13ae7
commit f8d0b72ff4
31 changed files with 49 additions and 24 deletions

View File

@@ -2,6 +2,7 @@
// Project: https://github.com/expressjs/body-parser
// Definitions by: Santi Albo <https://github.com/santialbo>, Vilic Vane <https://github.com/vilic>, Jonathan Häberle <https://github.com/dreampulse>, Gevik Babakhani <https://github.com/blendsdk>, Tomasz Łaziuk <https://github.com/tlaziuk>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
/// <reference types="node" />

View File

@@ -2,7 +2,7 @@
// Project: https://github.com/dwhieb/documentdb-session#readme
// Definitions by: Daniel Rosenwasser <https://github.com/DanielRosenwasser>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.2
// TypeScript Version: 2.3
import session = require("express-session");

View File

@@ -2,7 +2,7 @@
// Project: https://github.com/eggjs/egg
// Definitions by: Eward Song <https://github.com/sheperdwind>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.2
// TypeScript Version: 2.3
import * as accepts from 'accepts';
import * as KoaApplication from 'koa';

View File

@@ -2,6 +2,7 @@
// Project: https://github.com/AdamPflug/express-brute-redis
// Definitions by: Scott Harwell <https://github.com/scottharwell>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
import { ClientOpts } from "redis";

View File

@@ -2,6 +2,7 @@
// Project: https://github.com/aredo/express-enforces-ssl
// Definitions by: Kevin Stubbs <https://github.com/kevinstubbs>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
import { Request, Response, NextFunction } from 'express';

View File

@@ -2,6 +2,7 @@
// Project: https://github.com/fiznool/express-mongo-sanitize#readme
// Definitions by: Eric Byers <https://github.com/ericbyers>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
import express = require('express');

View File

@@ -2,6 +2,7 @@
// Project: https://github.com/nfriedly/express-rate-limit
// Definitions by: Cyril Schumacher <https://github.com/cyrilschumacher>, makepost <https://github.com/makepost>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
import express = require("express");

View File

@@ -2,6 +2,7 @@
// Project: https://github.com/askhogan/express-sanitized
// Definitions by: Chris Barth <https://github.com/cjbarth>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
import * as express from "express";

View File

@@ -174,7 +174,12 @@ interface RequestRanges extends Array<ByteRange> { type: string; }
interface Errback { (err: Error): void; }
interface Request extends http.IncomingMessage, Express.Request {
interface Request<
Body = any,
Query = any,
Params = any,
Cookies = any
> extends http.IncomingMessage, Express.Request {
/**
* Return request header.
@@ -435,14 +440,14 @@ interface Request extends http.IncomingMessage, Express.Request {
xhr: boolean;
//body: { username: string; password: string; remember: boolean; title: string; };
body: any;
body: Body;
//cookies: { string; remember: boolean; };
cookies: any;
cookies: Cookies;
method: string;
params: any;
params: Params;
/**
* Clear cookie `name`.
@@ -452,7 +457,7 @@ interface Request extends http.IncomingMessage, Express.Request {
*/
clearCookie(name: string, options?: any): Response;
query: any;
query: Query;
route: any;

View File

@@ -3,6 +3,7 @@
// Definitions by: Hiroki Horiuchi <https://github.com/horiuchi>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// Definitions by: Jacob Bogers <https://github.com/jacobbogers
// TypeScript Version: 2.3
/// <reference types="node" />

View File

@@ -17,9 +17,10 @@ namespace express_tests {
next();
});
app.use((err: any, req: express.Request, res: express.Response, next: express.NextFunction) => {
console.error(err);
next(err);
app.use((err: any, req: express.Request<{ hello: string; }>, res: express.Response, next: express.NextFunction) => {
console.log(req.body.hello);
console.error(err);
next(err);
});
app.get('/', (req, res) => {

View File

@@ -2,7 +2,7 @@
// Project: http://expressjs.com
// Definitions by: Boris Yankov <https://github.com/borisyankov>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.2
// TypeScript Version: 2.3
/* =================== USAGE ===================
@@ -76,7 +76,12 @@ declare namespace e {
interface IRouterMatcher<T> extends core.IRouterMatcher<T> { }
interface MediaType extends core.MediaType { }
interface NextFunction extends core.NextFunction { }
interface Request extends core.Request { }
interface Request<
Body = any,
Query = any,
Params = any,
Cookies = any
> extends core.Request<Body, Query, Params, Cookies> { }
interface RequestHandler extends core.RequestHandler { }
interface RequestParamHandler extends core.RequestParamHandler { }
export interface Response extends core.Response { }

View File

@@ -3,6 +3,7 @@
// Definitions by: Maxime LUCE <https://github.com/SomaticIT>
// FindQ <https://github.com/FindQ>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
declare namespace i18n {
interface ConfigurationOptions {

View File

@@ -2,7 +2,7 @@
// Project: https://github.com/koa-modules/morgan
// Definitions by: Vesa Poikajärvi <https://github.com/vesse>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.1
// TypeScript Version: 2.3
import { IncomingMessage, ServerResponse } from 'http';
import * as Koa from 'koa';

View File

@@ -3,7 +3,7 @@
// Definitions by: James Roland Cabresos <https://github.com/staticfunction>
// Paolo Scanferla <https://github.com/pscanf>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.2
// TypeScript Version: 2.3
import express = require('express');

View File

@@ -6,7 +6,7 @@
// Michael Ledin <https://github.com/mxl>
// HyunSeob Lee <https://github.com/hyunseob>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.1
// TypeScript Version: 2.3
import * as express from 'express';

View File

@@ -2,6 +2,7 @@
// Project: https://github.com/shutterstock/node-errors
// Definitions by: Ian Copp <https://github.com/icopp>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
import * as express from 'express';

View File

@@ -2,6 +2,7 @@
// Project: https://github.com/fex-team/node-ral
// Definitions by: ssddi456 <https://github.com/ssddi456>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
import { EventEmitter } from 'events';
import { Request, Response, NextFunction } from "express";

View File

@@ -3,6 +3,7 @@
// Definitions by: Robbie Van Gorkom <https://github.com/vangorra>,
// Charles Irick <https://github.com/cirick>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
import { Request, RequestHandler } from "express";

View File

@@ -2,6 +2,7 @@
// Project: https://github.com/apollostack/optics-agent-js#readme
// Definitions by: Crevil <https://github.com/crevil>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
import { GraphQLSchema } from "graphql";
import { Request, Response } from "express";

View File

@@ -2,7 +2,7 @@
// Project: https://github.com/ripjar/passport-client-cert
// Definitions by: Sean Warner <https://github.com/warnersean>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.1
// TypeScript Version: 2.3
import { Strategy as PassportStrategy } from 'passport-strategy';
import { Request } from 'express';

View File

@@ -2,7 +2,7 @@
// Project: https://github.com/nicholastay/passport-discord#readme
// Definitions by: Gonthier Renaud <https://github.com/kzay>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.2
// TypeScript Version: 2.3
/** Declaration file generated by dts-gen */
import * as passport from 'passport';

View File

@@ -2,7 +2,7 @@
// Project: https://github.com/jaredhanson/passport-facebook
// Definitions by: James Roland Cabresos <https://github.com/staticfunction>, Lucas Acosta <https://github.com/lucasmacosta>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.2
// TypeScript Version: 2.3
import passport = require('passport');
import express = require('express');

View File

@@ -2,7 +2,7 @@
// Project: https://github.com/jaredhanson/passport-github
// Definitions by: Yasunori Ohoka <https://github.com/yasupeke>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.2
// TypeScript Version: 2.3
import passport = require('passport');
import express = require('express');

View File

@@ -3,7 +3,7 @@
// Definitions by: Yasunori Ohoka <https://github.com/yasupeke>
// Maarten Mulders <https://github.com/mthmulders>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.2
// TypeScript Version: 2.3
import passport = require('passport');
import express = require('express');

View File

@@ -2,7 +2,7 @@
// Project: https://github.com/jaredhanson/passport-oauth2#readme
// Definitions by: Pasi Eronen <https://github.com/pasieronen>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.2
// TypeScript Version: 2.3
import { Request } from 'express';
import { Strategy } from 'passport';

View File

@@ -2,6 +2,7 @@
// Project: https://github.com/bergie/passport-saml
// Definitions by: Chris Barth <https://github.com/cjbarth>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
import passport = require('passport');
import express = require('express');

View File

@@ -3,7 +3,7 @@
// Definitions by: briman0094 <https://github.com/briman0094>
// Maxime LUCE <https://github.com/SomaticIT>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.2
// TypeScript Version: 2.3
import passport = require('passport');
import express = require('express');

View File

@@ -2,7 +2,7 @@
// Project: https://www.npmjs.com/package/swagger-node-runner
// Definitions by: Michael Mrowetz <https://github.com/micmro>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.2
// TypeScript Version: 2.3
/* =================== USAGE ===================

View File

@@ -2,7 +2,7 @@
// Project: https://github.com/fex-team/yog-log
// Definitions by: ssddi456 <https://github.com/ssddi456>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.2
// TypeScript Version: 2.3
import { Request, Response, NextFunction } from "express";

View File

@@ -2,6 +2,7 @@
// Project: https://github.com/fex-team/yog2-kernel
// Definitions by: ssddi456 <https://github.com/ssddi456>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
import * as express from "express";
import * as _ from "lodash";