mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-11 20:40:20 +00:00
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:
@@ -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);
|
||||
Vendored
+26
@@ -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;
|
||||
@@ -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"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json"
|
||||
}
|
||||
Reference in New Issue
Block a user