Here is the function that simplifies the formatting of console outputs:
function generateConsoleMethodParametersForFormattedOutput(
formattedOutputData: Array<[string, { [CSS_Key: string]: string; }]>
): Array<string> {
const outputContents: Array<string> = [];
const CSS_DeclarationsForEachContent: Array<string> = [];
for (const singleFormattedOutputData of formattedOutputData) {
outputContents.push(`%c${singleFormattedOutputData[0]}`);
let CSS_Declarations: string = "";
for (const [ CSS_Key, CSS_Value ] of Object.entries(singleFormattedOutputData[1])) {
CSS_Declarations = `${CSS_Declarations}${CSS_Key}: ${CSS_Value};`;
}
CSS_DeclarationsForEachContent.push(CSS_Declarations);
}
return [ outputContents.join(""), ...CSS_DeclarationsForEachContent ];
}
Now we can make the formatting output as:
console.log(...generateConsoleMethodParametersForFormattedOutput([
[ " Red bold ", { background: "red", color: "white", "font-weight": "bold", "border-radius": "4px" } ],
[ " Blue italic", { color: "blue", "font-style": "italic" } ]
]));
What if we want to add the conditional element in generateConsoleMethodParametersForFormattedOutput([])?
The basic approach is:
[ "RequiredElement", condition ? [ "ConditionlaElement" ] : [] ]
Here, we have the TypeScript error:
console.log(...generateConsoleMethodParametersForFormattedOutput([
[ " Red bold ", { background: "red", color: "white", "font-weight": "bold", "border-radius": "4px" } ],
[ " Blue italic", { color: "blue", "font-style": "italic" } ],
...mockCondition ? [ [ " Teal ", { color: "teal" } ] ] : []
]));
Type '(string | { color: string; })[]' is not assignable to type '[string, { [CSS_Key: string]: string; }]'.
Target requires 2 element(s) but source may have fewer.(2322)
But the compiled JavaScript works:
My mistake or TypeScrirpt bug?

printFormattedErrorLogToConsoleprotected static method ofAbstractFrontEndLoggerclass of[email protected]. (The usage isimport {AbstractFrontEndLogger} from hikari-es-extensions/BrowserJS). Sorry for not available yet documentation...@yamato-daiwa/es-extensions. I am very sorry if you don't need it anymore.@yamato-daiwa/es-extensionstag in StackOverflow because I have not enough reputation to create it myself. But if it will be created I'll watch for the new questions with this badge and answer to it.