Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions types/__typetests__/handlebars.tst.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
HandlebarsTemplatable,
HandlebarsTemplateDelegate,
HandlebarsTemplates,
PrecompileOptions,
TemplateSpecification,
KnownHelpers,
BuiltinHelperName,
Expand Down Expand Up @@ -53,16 +54,24 @@ describe('Handlebars.compile', () => {
// Handlebars.precompile
// ---------------------------------------------------------------------------
describe('Handlebars.precompile', () => {
test('returns TemplateSpecification', () => {
test('returns a string without srcName', () => {
expect(Handlebars.precompile('{{name}}')).type.toBe<string>();
expect(
Handlebars.precompile('{{name}}')
).type.toBe<TemplateSpecification>();
Handlebars.precompile('{{name}}', { knownHelpersOnly: true })
).type.toBe<string>();
});

test('accepts PrecompileOptions', () => {
test('returns the code and source map with srcName', () => {
expect(
Handlebars.precompile('test', { srcName: 'a.hbs', destName: 'a.js' })
).type.not.toRaiseError();
).type.toBe<{ code: string; map: string }>();
});

test('returns either form when srcName is not known', () => {
const options: PrecompileOptions = {};
expect(Handlebars.precompile('test', options)).type.toBe<
string | { code: string; map: string }
>();
});
});

Expand Down
12 changes: 10 additions & 2 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,16 @@ declare namespace Handlebars {
): HandlebarsTemplateDelegate<T>;
export function precompile(
input: any,
options?: PrecompileOptions
): TemplateSpecification;
options: PrecompileOptions & { srcName: string }
): { code: string; map: string };
export function precompile(
input: any,
options?: PrecompileOptions & { srcName?: undefined }
): string;
export function precompile(
input: any,
options: PrecompileOptions
): string | { code: string; map: string };
export function template<T = any>(
precompilation: TemplateSpecification
): HandlebarsTemplateDelegate<T>;
Expand Down