From 321137bdd3b4b5a0bfee41f17890fca08161949f Mon Sep 17 00:00:00 2001 From: zhangwenxi Date: Mon, 20 Aug 2018 17:59:58 +0800 Subject: [PATCH 1/3] add express-wechat-access types --- .../express-wechat-access-tests.ts | 18 ++++++++++ types/express-wechat-access/index.d.ts | 35 +++++++++++++++++++ types/express-wechat-access/tsconfig.json | 23 ++++++++++++ types/express-wechat-access/tslint.json | 11 ++++++ 4 files changed, 87 insertions(+) create mode 100644 types/express-wechat-access/express-wechat-access-tests.ts create mode 100644 types/express-wechat-access/index.d.ts create mode 100644 types/express-wechat-access/tsconfig.json create mode 100644 types/express-wechat-access/tslint.json diff --git a/types/express-wechat-access/express-wechat-access-tests.ts b/types/express-wechat-access/express-wechat-access-tests.ts new file mode 100644 index 0000000000..659c5b3639 --- /dev/null +++ b/types/express-wechat-access/express-wechat-access-tests.ts @@ -0,0 +1,18 @@ +import express = require('express'); +import * as weAccessMiddleware from 'express-wechat-access'; + +const app: express.Application = express(); + +const options: weAccessMiddleware.IWeAccessMidOption = { + appId: 'xxxxx', + appSecret: 'xxxxx' +}; + +app.use( + weAccessMiddleware( + options, + e => { + console.error(e); + } + ) +); diff --git a/types/express-wechat-access/index.d.ts b/types/express-wechat-access/index.d.ts new file mode 100644 index 0000000000..f871d1733e --- /dev/null +++ b/types/express-wechat-access/index.d.ts @@ -0,0 +1,35 @@ +// Type definitions for express-wechat-access 1.1 +// Project: https://github.com/simmons8616/express-wechat-access +// Definitions by: Simmons Zhang +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.2 + +/// +/// + +import { Response, NextFunction } from 'express'; +import * as http from 'http'; +import { EventEmitter } from 'events'; + +interface IMidOption { + accessTokenUrl?: string; + ticketUrl?: string; + appId: string; + appSecret: string; + https?: boolean; +} + +type IMiddleware = (req: any, res: Response | http.ServerResponse, next: NextFunction) => any; + +declare function weAccessMiddleware( + options: IMidOption, + errorHandler?: (e: any) => any +): IMiddleware; + +declare namespace weAccessMiddleware { + interface IWeAccessMidOption extends IMidOption {} + + interface IWeAccessMiddleware extends IMiddleware, EventEmitter, Function {} +} + +export = weAccessMiddleware; diff --git a/types/express-wechat-access/tsconfig.json b/types/express-wechat-access/tsconfig.json new file mode 100644 index 0000000000..e24d740f2c --- /dev/null +++ b/types/express-wechat-access/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "express-wechat-access-tests.ts" + ] +} diff --git a/types/express-wechat-access/tslint.json b/types/express-wechat-access/tslint.json new file mode 100644 index 0000000000..886d87b3b7 --- /dev/null +++ b/types/express-wechat-access/tslint.json @@ -0,0 +1,11 @@ +{ + "extends": "dtslint/dt.json", + "rules": { + "interface-name": false, + "no-empty-interface": false, + "no-namespace": false, + "no-reference-import": false, + "no-var-keyword": false, + "strict-export-declare-modifiers": false + } +} From 8415d3ef91da5dc3f2aa6aea4b1374d534c03801 Mon Sep 17 00:00:00 2001 From: simmons8616 Date: Mon, 20 Aug 2018 18:04:42 +0800 Subject: [PATCH 2/3] add express-wechat-access types --- types/express-wechat-access/tsconfig.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/express-wechat-access/tsconfig.json b/types/express-wechat-access/tsconfig.json index e24d740f2c..9924528f6b 100644 --- a/types/express-wechat-access/tsconfig.json +++ b/types/express-wechat-access/tsconfig.json @@ -7,7 +7,7 @@ "noImplicitAny": true, "noImplicitThis": true, "strictFunctionTypes": true, - "strictNullChecks": true, + "strictNullChecks": false, "baseUrl": "../", "typeRoots": [ "../" From 461268efc574fdd1efffb065d64b776389c3a28f Mon Sep 17 00:00:00 2001 From: simmons8616 Date: Thu, 23 Aug 2018 17:55:46 +0800 Subject: [PATCH 3/3] modify tsconfig and tslint.json --- .../express-wechat-access-tests.ts | 2 +- types/express-wechat-access/index.d.ts | 31 ++++++++++--------- types/express-wechat-access/tsconfig.json | 2 +- types/express-wechat-access/tslint.json | 12 +------ 4 files changed, 20 insertions(+), 27 deletions(-) diff --git a/types/express-wechat-access/express-wechat-access-tests.ts b/types/express-wechat-access/express-wechat-access-tests.ts index 659c5b3639..60cc5d9d88 100644 --- a/types/express-wechat-access/express-wechat-access-tests.ts +++ b/types/express-wechat-access/express-wechat-access-tests.ts @@ -3,7 +3,7 @@ import * as weAccessMiddleware from 'express-wechat-access'; const app: express.Application = express(); -const options: weAccessMiddleware.IWeAccessMidOption = { +const options: weAccessMiddleware.WeAccessMidOption = { appId: 'xxxxx', appSecret: 'xxxxx' }; diff --git a/types/express-wechat-access/index.d.ts b/types/express-wechat-access/index.d.ts index f871d1733e..fb0d58701d 100644 --- a/types/express-wechat-access/index.d.ts +++ b/types/express-wechat-access/index.d.ts @@ -5,31 +5,34 @@ // TypeScript Version: 2.2 /// -/// import { Response, NextFunction } from 'express'; import * as http from 'http'; import { EventEmitter } from 'events'; -interface IMidOption { - accessTokenUrl?: string; - ticketUrl?: string; - appId: string; - appSecret: string; - https?: boolean; -} - -type IMiddleware = (req: any, res: Response | http.ServerResponse, next: NextFunction) => any; +type WeMiddleware = (req: any, res: Response | http.ServerResponse, next: NextFunction) => any; declare function weAccessMiddleware( - options: IMidOption, + options: { + accessTokenUrl?: string; + ticketUrl?: string; + appId: string; + appSecret: string; + https?: boolean; + }, errorHandler?: (e: any) => any -): IMiddleware; +): WeMiddleware; declare namespace weAccessMiddleware { - interface IWeAccessMidOption extends IMidOption {} + interface WeAccessMidOption { + accessTokenUrl?: string; + ticketUrl?: string; + appId: string; + appSecret: string; + https?: boolean; + } - interface IWeAccessMiddleware extends IMiddleware, EventEmitter, Function {} + interface WeAccessMiddleware extends WeMiddleware, EventEmitter, Function {} } export = weAccessMiddleware; diff --git a/types/express-wechat-access/tsconfig.json b/types/express-wechat-access/tsconfig.json index 9924528f6b..e24d740f2c 100644 --- a/types/express-wechat-access/tsconfig.json +++ b/types/express-wechat-access/tsconfig.json @@ -7,7 +7,7 @@ "noImplicitAny": true, "noImplicitThis": true, "strictFunctionTypes": true, - "strictNullChecks": false, + "strictNullChecks": true, "baseUrl": "../", "typeRoots": [ "../" diff --git a/types/express-wechat-access/tslint.json b/types/express-wechat-access/tslint.json index 886d87b3b7..3db14f85ea 100644 --- a/types/express-wechat-access/tslint.json +++ b/types/express-wechat-access/tslint.json @@ -1,11 +1 @@ -{ - "extends": "dtslint/dt.json", - "rules": { - "interface-name": false, - "no-empty-interface": false, - "no-namespace": false, - "no-reference-import": false, - "no-var-keyword": false, - "strict-export-declare-modifiers": false - } -} +{ "extends": "dtslint/dt.json" }