diff --git a/koa-hbs/index.d.ts b/koa-hbs/index.d.ts index 8adfeaf20f..51c609e296 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 by: Jacob Malone , Mudkip // 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 diff --git a/koa-hbs/koa-hbs-tests.ts b/koa-hbs/koa-hbs-tests.ts index 647eee7f22..3c86a51cad 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 ctx.render('index', { title: 'Hello World!' }); });