From b2ff010b24dc00bd3da9a8e6615246e0bf222839 Mon Sep 17 00:00:00 2001 From: Daniel Melcer Date: Tue, 25 Feb 2020 15:58:13 -0500 Subject: [PATCH] twig: Added overload to Template.render when allow_async=false (#42593) * Added overload to twig Template.render when allow_async=false * twig: added test to demonstrate behavior with allow_async * twig: added test with unknown boolean * twig: fixed whitespace --- types/twig/index.d.ts | 2 ++ types/twig/twig-tests.ts | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/types/twig/index.d.ts b/types/twig/index.d.ts index fcfb1806dd..04a3d1dbdf 100644 --- a/types/twig/index.d.ts +++ b/types/twig/index.d.ts @@ -3,6 +3,7 @@ // Definitions by: Carlos Ballesteros Velasco // Tim Schumacher // Maik Tizziani +// Daniel Melcer // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // Imported from: https://github.com/soywiz/typescript-node-definitions/twig.d.ts @@ -24,6 +25,7 @@ export interface Parameters { export interface Template { reset(blocks: any): void; + render(context?: any, params?: any, allow_async?: false): string; render(context?: any, params?: any, allow_async?: boolean): string | Promise; renderAsync(context?: any, params?: any): Promise; importFile(file: string): Template; diff --git a/types/twig/twig-tests.ts b/types/twig/twig-tests.ts index 39fbdc804d..70cced0a99 100644 --- a/types/twig/twig-tests.ts +++ b/types/twig/twig-tests.ts @@ -20,6 +20,17 @@ const params: twig.Parameters = { const temp: twig.Template = twig.twig(params); +const result: string = temp.render(); + +const async_result: string | Promise = temp.render(undefined, undefined, true); + +function twig_async_param(b: boolean) { + const maybe_async_result: string | Promise = temp.render(undefined, undefined, b); +} + +twig_async_param(true); +twig_async_param(false); + const compOpts: twig.CompileOptions = { filename: str, settings: value