Adding the types makes sense.
Only the else if else statement could be replaced. My suggestion based on your example
const parseStringToHtml = (line = "", isFirstLine = false): string => { if (!line) return "<br />"; if (isFirstLine) return `<h1>${line}</h1>`; return `<p>${line}</p>`; };
edited
I'd suggest putting the line argument in the function first, as line is more important and isFirstLine can have a default value
isFirstLine
true i just copy paste it and didn't read the arguments.
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Adding the types makes sense.
Only the else if else statement could be replaced. My suggestion based on your example
edited
I'd suggest putting the line argument in the function first, as line is more important and
isFirstLine
can have a default valuetrue i just copy paste it and didn't read the arguments.