diff --git a/types/hbs/hbs-tests.ts b/types/hbs/hbs-tests.ts new file mode 100644 index 0000000000..a1baa73ca7 --- /dev/null +++ b/types/hbs/hbs-tests.ts @@ -0,0 +1,29 @@ +import * as express from 'express'; + +const app = express(); + +app.set('view engine', 'html'); + +import hbs = require('hbs'); + +// The idiom for this is +// app.engine('html', require('hbs').__express); +// However this undermines the test since the return type of require() is any +app.engine('html', hbs.__express); + +hbs.registerHelper('helper_name', (testParm: number) => testParm++); +hbs.registerPartial('partial_name', 'partial value'); + +hbs.registerPartials(__dirname + '/views/partials'); + +hbs.registerPartials(__dirname + '/views/partials', () => {}); + +hbs.localsAsTemplateData(app); + +const safeString = new hbs.handlebars.SafeString("string"); + +const instance1 = hbs.create(); +const instance2 = hbs.create(); + +app.engine('html', instance1.__express); +app.engine('hbs', instance2.__express); diff --git a/types/hbs/index.d.ts b/types/hbs/index.d.ts new file mode 100644 index 0000000000..1b3a36c4be --- /dev/null +++ b/types/hbs/index.d.ts @@ -0,0 +1,26 @@ +// Type definitions for hbs 4.0 +// Project: https://github.com/pillarjs/hbs +// Definitions by: David Muller +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.3 + +import handlebars = require('handlebars'); + +type handlebarsModule = typeof handlebars; + +interface hbsModule { + readonly handlebars: handlebarsModule; + localsAsTemplateData(app: any): void; + registerHelper(helperName: string, helperFunction: (...args: any[]) => any): void; + registerPartial(partialName: string, partialValue: string): void; + registerPartials(directoryName: string, callback?: () => void): void; + __express(filename: string, options: any, cb: (...args: any[]) => any): any; +} + +interface hbsModuleWithCreate extends hbsModule { + create(handlebars?: handlebarsModule): hbsModule; +} + +declare var baseModule: hbsModuleWithCreate; + +export = baseModule; diff --git a/types/hbs/tsconfig.json b/types/hbs/tsconfig.json new file mode 100644 index 0000000000..f16c9e251f --- /dev/null +++ b/types/hbs/tsconfig.json @@ -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", + "hbs-tests.ts" + ] +} \ No newline at end of file diff --git a/types/hbs/tslint.json b/types/hbs/tslint.json new file mode 100644 index 0000000000..f93cf8562a --- /dev/null +++ b/types/hbs/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "dtslint/dt.json" +}