You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
So, to use the knownHelpersOnly option with custom helpers, you have to cast the knownHelpers in order to by pass typescript checks;
functiongiven(...args: any[]): string{constoptions=args.pop();if(options.fn){letcomplete=true;constproxy=newProxy(this,{get(context,prop: string): object{if(!(propincontext)){complete=false;}returncontext[prop];},});consttext=options.fn(proxy);returncomplete ? text : '';}returnargs.some((a: string): boolean=>!a) ? '' : args.join(' ');}consttemplateOptions={helpers: {
first,},};constcompilerOptions={knownHelpers: {first: true}asunknown,// Without this `unknown` compilation failsknownHelpersOnly: true,};Hanblebars.compile('My nice template {{first "text"}}',compilerOptions)({},templateOptions);
The produced error (without using the unknown cast) is the following:
TypeScript diagnostics (customize using `[jest-config].globals.ts-jest.diagnostics` option):
src/index.test.ts:93:41 - error TS2345: Argument of type '{ knownHelpers: { first: boolean; }; knownHelpersOnly: boolean; }' is not assignable to parameter of type 'CompileOptions'.
Types of property 'knownHelpers' are incompatible.
Type '{ first: boolean; }' has no properties in common with type '{ helperMissing?: boolean; blockHelperMissing?: boolean; each?: boolean; if?: boolean; unless?: boolean; with?: boolean; log?: boolean; lookup?: boolean; }'.
Thanks for the offer. I have pushed a slightly different fix. I think in order to get proper auto-completion for the builtin-helpers in IDEs, it is better to keep the builtin names, but still allow any other name.
Before filing issues, please check the following points first:
This will probably help you to get a solution faster.
For bugs, it would be great to have a PR with a failing test-case.
Currently Handlebar's typescript definition don't allow to specify custom helpers on the
knownHelper
option.So, to use the
knownHelpersOnly
option with custom helpers, you have to cast theknownHelpers
in order to by pass typescript checks;The produced error (without using the
unknown
cast) is the following:Shouldn't the
CompilerOptions
have the follow definition?:(Am I not getting something?. I'm willing to send the PR if this is the right fix)
The text was updated successfully, but these errors were encountered: