From 5be6b2f25f883734e300f3cbcd3f938878d6edb7 Mon Sep 17 00:00:00 2001 From: Nils Knappmeier Date: Tue, 3 Sep 2019 21:32:41 +0200 Subject: [PATCH] fix typings of resolvePartial-options - derived from the object structure seen in the debugger closes #1534 --- Gruntfile.js | 6 +++--- types/index.d.ts | 13 +++++++++++-- types/test.ts | 5 +++-- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index fad1be391..7e028a052 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -5,15 +5,15 @@ module.exports = function(grunt) { pkg: grunt.file.readJSON('package.json'), eslint: { - options: { - }, files: [ '*.js', 'bench/**/*.js', 'tasks/**/*.js', 'lib/**/!(*.min|parser).js', 'spec/**/!(*.amd|json2|require).js', - 'integration-testing/**/*.js' + 'integration-testing/multi-nodejs-test/*.js', + 'integration-testing/webpack-test/*.js', + 'integration-testing/webpack-test/src/*.js' ] }, diff --git a/types/index.d.ts b/types/index.d.ts index 99ec21364..a142119a4 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -8,6 +8,7 @@ * - Sergei Dorogin * - webbiesdk * - Andrew Leedham + * - Nils Knappmeier * For full history prior to their migration to handlebars.js, please see: * https://github.com/DefinitelyTyped/DefinitelyTyped/commits/1ce60bdc07f10e0b076778c6c953271c072bc894/types/handlebars/index.d.ts */ @@ -21,7 +22,6 @@ declare namespace Handlebars { export type Template = TemplateDelegate|string; export interface RuntimeOptions { - name?: string; partial?: boolean; depths?: any[]; helpers?: { [name: string]: Function }; @@ -150,11 +150,20 @@ declare namespace Handlebars { Hash(hash: hbs.AST.Hash): void; } + + export interface ResolvePartialOptions { + name: string; + helpers?: { [name: string]: Function }; + partials?: { [name: string]: HandlebarsTemplateDelegate }; + decorators?: { [name: string]: Function }; + data?: any; + } + export namespace VM { /** * @deprecated */ - export function resolvePartial(partial: HandlebarsTemplateDelegate | undefined, context: any, options: RuntimeOptions): HandlebarsTemplateDelegate; + export function resolvePartial(partial: HandlebarsTemplateDelegate | undefined, context: any, options: ResolvePartialOptions): HandlebarsTemplateDelegate; } } diff --git a/types/test.ts b/types/test.ts index 24951f48b..3f762c210 100644 --- a/types/test.ts +++ b/types/test.ts @@ -5,6 +5,7 @@ */ import * as Handlebars from 'handlebars'; +import ResolvePartialOptions = Handlebars.ResolvePartialOptions; const context = { author: { firstName: 'Alan', lastName: 'Johnson' }, @@ -92,8 +93,8 @@ const parsedTmplWithoutOptions = Handlebars.parse('

Hello, my name is {{name}} // Custom partial resolution. const originalResolvePartial = Handlebars.VM.resolvePartial; -Handlebars.VM.resolvePartial = (partial: HandlebarsTemplateDelegate | undefined, context: any, options: RuntimeOptions): HandlebarsTemplateDelegate => { - const name = options.name; +Handlebars.VM.resolvePartial = (partial: HandlebarsTemplateDelegate | undefined, context: any, options: ResolvePartialOptions): HandlebarsTemplateDelegate => { + const name = options.name.replace(/my/,'your'); // transform name. options.name = name; return originalResolvePartial(partial, context, options);