-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change-type: patch
- Loading branch information
Showing
2 changed files
with
28 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,29 @@ | ||
declare module 'promised-handlebars' { | ||
import type Handlebars from 'handlebars'; | ||
import type HandlebarsNS from 'handlebars'; | ||
|
||
const fn: (hb: typeof Handlebars) => typeof Handlebars; | ||
// Extend the Handlebars type to include an async `compile` method | ||
type Handlebars = typeof HandlebarsNS; | ||
|
||
// Convert the template delegate to async | ||
// Note: this was tested with handlebars 4.7.8 | ||
type HandlebarsTemplateDelegate<T> = Handlebars.TemplateDelegate<T>; | ||
type HandlebarsTemplateDelegateArgs<T> = Parameters< | ||
HandlebarsTemplateDelegate<T> | ||
>; | ||
type HandlebarsTemplateDelegateReturn<T> = ReturnType< | ||
HandlebarsTemplateDelegate<T> | ||
>; | ||
type HandlebarsTemplateDelegateAsync<T> = ( | ||
...args: HandlebarsTemplateDelegateArgs<T> | ||
) => Promise<HandlebarsTemplateDelegateReturn<T>>; | ||
|
||
// Create a new Handlebars interface with an updated compile function | ||
type CompileArgs = Parameters<Handlebars['compile']>; | ||
interface HandlebarsAsync extends Handlebars { | ||
compile: <T>(...args: CompileArgs) => HandlebarsTemplateDelegateAsync<T>; | ||
} | ||
|
||
// Define the function exported by the module | ||
const fn: (hb: Handlebars) => HandlebarsAsync; | ||
export = fn; | ||
} |