Fix types
This commit is contained in:
parent
d4e72e4a0b
commit
029ac07fa2
|
@ -83,20 +83,22 @@ function createTemplate(string: string, opts?: ProcessOptions) {
|
||||||
* @param {object|undefined} [opts] optional - specify some options for processing.
|
* @param {object|undefined} [opts] optional - specify some options for processing.
|
||||||
* @returns {Promise<object|array>} The structure input, as fully updated as possible.
|
* @returns {Promise<object|array>} The structure input, as fully updated as possible.
|
||||||
*/
|
*/
|
||||||
export async function processObject(
|
export async function processObject<T extends Record<string, any>>(
|
||||||
object: { [x: string]: any },
|
object: T,
|
||||||
context: object,
|
context: object,
|
||||||
opts?: { noHelpers?: boolean; escapeNewlines?: boolean; onlyFound?: boolean }
|
opts?: { noHelpers?: boolean; escapeNewlines?: boolean; onlyFound?: boolean }
|
||||||
): Promise<object | Array<any>> {
|
): Promise<T> {
|
||||||
testObject(object)
|
testObject(object)
|
||||||
for (let key of Object.keys(object || {})) {
|
for (const key of Object.keys(object || {})) {
|
||||||
if (object[key] != null) {
|
if (object[key] != null) {
|
||||||
let val = object[key]
|
const val = object[key]
|
||||||
|
let parsedValue
|
||||||
if (typeof val === "string") {
|
if (typeof val === "string") {
|
||||||
object[key] = await processString(object[key], context, opts)
|
parsedValue = await processString(object[key], context, opts)
|
||||||
} else if (typeof val === "object") {
|
} else if (typeof val === "object") {
|
||||||
object[key] = await processObject(object[key], context, opts)
|
parsedValue = await processObject(object[key], context, opts)
|
||||||
}
|
}
|
||||||
|
;(object as any)[key] = parsedValue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return object
|
return object
|
||||||
|
|
Loading…
Reference in New Issue