handlebars-lang / handlebars.js

Minimal templating on steroids.
http://handlebarsjs.com
MIT License
17.96k stars 2.04k forks source link

Use type `Record<string, any>` for `HelperOptions.hash` #2001

Closed jaylinski closed 1 year ago

jaylinski commented 1 year ago

Discussed in https://github.com/handlebars-lang/handlebars.js/discussions/2000

Originally posted by **dargmuesli** September 8, 2023 Could this `any` be turned to `Record`? https://github.com/handlebars-lang/handlebars.js/blob/ae83edd5c490ccaa41e3d345e5068378e6207837/types/index.d.ts#L48 `Record` would be too strict, I guess.
jaylinski commented 1 year ago

Yes, I think we can change the type to Record<string, any>. The documentation says it's always an object:

https://handlebarsjs.com/guide/block-helpers.html#hash-arguments

If the template provides no hash arguments, Handlebars will automatically pass an empty object ({}), so you don't need to check for the existence of hash arguments.