From 9b396a5a42900511092b65d7f3cecde1ff8d32dd Mon Sep 17 00:00:00 2001 From: mudkip Date: Mon, 13 Feb 2017 19:29:55 +0800 Subject: [PATCH 1/3] Fix type declaration of koa-hbs --- koa-hbs/index.d.ts | 61 +++++++++++++++++++++++----------------------- 1 file changed, 31 insertions(+), 30 deletions(-) diff --git a/koa-hbs/index.d.ts b/koa-hbs/index.d.ts index 8adfeaf20f..0b800418e7 100644 --- a/koa-hbs/index.d.ts +++ b/koa-hbs/index.d.ts @@ -1,22 +1,21 @@ -// Type definitions for koa-favicon v2.x +// Type definitions for koa-hbs v1.x // Project: https://github.com/gilt/koa-hbs // Definitions by: Jacob Malone // Definitions: https://github.com/jcbmln/DefinitelyTyped /* =================== USAGE =================== - import * as Hbs from "koa-hbs"; import * as Koa from "koa"; +....import hbs = require("koa-hbs"); - var hbs = new Hbs(); var app = new Koa(); app.use(hbs.middleware({ viewPath: __dirname + '/views' })); - app.use(function *() { - yield this.render('main', { + app.use(async (ctx, next) => { + await ctx.render('main', { title: 'koa-hbs' }); }); @@ -25,31 +24,33 @@ /// -declare module "koa-hbs" { +import * as Koa from "koa"; - import * as Koa from "koa"; - - namespace Hbs { - export interface Middleware { - viewPath: Array | string, - handlebars?: Function, - templateOptions?: {}, - extname?: string, - partialsPath?: Array | string, - defaultLayout?: string, - layoutsPath?: string, - contentHelperName?: string, - blockHelperName?: string, - disableCache?: boolean - } +declare namespace Hbs { + export interface Middleware { + viewPath: Array | string, + handlebars?: Function, + templateOptions?: {}, + extname?: string, + partialsPath?: Array | string, + defaultLayout?: string, + layoutsPath?: string, + contentHelperName?: string, + blockHelperName?: string, + disableCache?: boolean } - - class Hbs { - constructor(); - - middleware(opts: Hbs.Middleware): any; - } - - namespace Hbs {} - export = Hbs; } + +declare class Hbs { + constructor(); + middleware(opts: Hbs.Middleware): any; +} + +declare const hbs: Hbs; +export = hbs; + +declare module "koa" { + export interface Context extends Request, Response { + render(tpl: string, locals?: {[key: string]: any}): Promise; + } +} \ No newline at end of file From 9d697c95a22d31d4a163b37628f5809a362f6938 Mon Sep 17 00:00:00 2001 From: mudkip Date: Mon, 13 Feb 2017 19:49:34 +0800 Subject: [PATCH 2/3] Update koa-hbs test file --- koa-hbs/koa-hbs-tests.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/koa-hbs/koa-hbs-tests.ts b/koa-hbs/koa-hbs-tests.ts index 647eee7f22..43c708b581 100644 --- a/koa-hbs/koa-hbs-tests.ts +++ b/koa-hbs/koa-hbs-tests.ts @@ -1,16 +1,15 @@ -import * as Hbs from 'koa-hbs'; import * as Koa from 'koa'; +import hbs = require("koa-hbs"); import * as Path from 'path'; const app = new Koa(); -const hbs = new Hbs(); app.use(hbs.middleware({ viewPath: Path.join(__dirname, './views') })); -app.use(function *(next: any) { - yield this.render('index', { +app.use(async (ctx, next) => { + await this.render('index', { title: 'Hello World!' }); }); From 25fef3a37b9cd808b9b4d6a68148dcfd50f927ba Mon Sep 17 00:00:00 2001 From: mudkip Date: Tue, 14 Feb 2017 10:12:50 +0800 Subject: [PATCH 3/3] Fix koa-hbs-tests.ts --- koa-hbs/index.d.ts | 2 +- koa-hbs/koa-hbs-tests.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/koa-hbs/index.d.ts b/koa-hbs/index.d.ts index 0b800418e7..51c609e296 100644 --- a/koa-hbs/index.d.ts +++ b/koa-hbs/index.d.ts @@ -1,6 +1,6 @@ // Type definitions for koa-hbs v1.x // Project: https://github.com/gilt/koa-hbs -// Definitions by: Jacob Malone +// Definitions by: Jacob Malone , Mudkip // Definitions: https://github.com/jcbmln/DefinitelyTyped /* =================== USAGE =================== diff --git a/koa-hbs/koa-hbs-tests.ts b/koa-hbs/koa-hbs-tests.ts index 43c708b581..3c86a51cad 100644 --- a/koa-hbs/koa-hbs-tests.ts +++ b/koa-hbs/koa-hbs-tests.ts @@ -9,7 +9,7 @@ app.use(hbs.middleware({ })); app.use(async (ctx, next) => { - await this.render('index', { + await ctx.render('index', { title: 'Hello World!' }); });