Add types for hbs npm package (#23091)

* Add types for hbs

* Use dtsg-gen generated tsconfig.json

* Add additional tests

* Now lints with less cheating

* Avoid losing type information
This commit is contained in:
DavidM77
2018-01-23 16:19:23 -08:00
committed by Andy
parent 4b720c2d25
commit 067defebd0
4 changed files with 81 additions and 0 deletions
+29
View File
@@ -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);
+26
View File
@@ -0,0 +1,26 @@
// Type definitions for hbs 4.0
// Project: https://github.com/pillarjs/hbs
// Definitions by: David Muller <https://github.com/davidm77>
// 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;
+23
View File
@@ -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"
]
}
+3
View File
@@ -0,0 +1,3 @@
{
"extends": "dtslint/dt.json"
}