From 637ccb0457019892f4492af398a706e0636ee6cf Mon Sep 17 00:00:00 2001 From: Junyi Date: Tue, 4 Jul 2023 19:41:20 +0700 Subject: [PATCH] fix(utils): fix json-template type checking logic (#2177) --- packages/core/utils/src/json-templates.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/packages/core/utils/src/json-templates.ts b/packages/core/utils/src/json-templates.ts index 00de502ea..0d3e422cc 100644 --- a/packages/core/utils/src/json-templates.ts +++ b/packages/core/utils/src/json-templates.ts @@ -92,20 +92,21 @@ const parseString = (() => { return matches.reduce((result, match, i) => { const parameter = parameters[i]; let value = objectPath.get(context, parameter.key); - const type = typeof value; - if (type === 'undefined') { - if (typeof parameter.defaultValue === 'undefined') { - return value; - } + if (typeof value === 'undefined') { value = parameter.defaultValue; } - if (type === 'function') { + if (typeof value === 'function') { value = value(); } - if (type === 'object') { + if (typeof value === 'object' && value !== null) { + return value; + } + + // Accommodate numbers as values. + if (matches.length === 1 && str.startsWith('{{') && str.endsWith('}}')) { return value; }