Просмотр исходного кода

fix: can't convert trArgs[0] to string error

Sv443 1 день назад
Родитель
Сommit
528e09cd6d
2 измененных файлов с 14 добавлено и 1 удалено
  1. 5 0
      .changeset/violet-ducks-tell.md
  2. 9 1
      lib/translation.ts

+ 5 - 0
.changeset/violet-ducks-tell.md

@@ -0,0 +1,5 @@
+---
+"@sv443-network/userutils": patch
+---
+
+Fix `can't convert trArgs[0] to string` error

+ 9 - 1
lib/translation.ts

@@ -388,8 +388,16 @@ const templateLiteralTransform: TransformTuple<string> = [
       }
     };
 
+    let notStringifiable = false;
+    try {
+      String(trArgs[0]);
+    }
+    catch {
+      notStringifiable = true;
+    }
+
     /** Whether the first args parameter is an object that doesn't implement a custom `toString` method */
-    const isArgsObject = trArgs[0] && typeof trArgs[0] === "object" && trArgs[0] !== null && String(trArgs[0]).startsWith("[object");
+    const isArgsObject = trArgs[0] && typeof trArgs[0] === "object" && trArgs[0] !== null && (notStringifiable || String(trArgs[0]).startsWith("[object"));
 
     if(isArgsObject && eachKeyInTrString(Object.keys(trArgs[0]!)))
       namedMapping();