For the part where you're describing what's possible or not in TypeScript/JS, though, you're incorrect:
You can't do something like title("hi") vs title({attr:123}, "hi")
Yes, you can. In JS it's trivial; in TypeScript, you can even do it while preserving type safety. Here's the function in TypeScript:
// First define which signatures are allowed
function title(content: string): string;
function title(attrs: Record<string, any>, content: string): string;
// Then, implement the function, handling the two possible cases:
function(contentOrAttrs: string | Record<string, any>, maybeContent?: string) {
const content = typeof contentOrAttrs === "string" ? contentOrAttrs : maybeContent!;
const attrs = typeof contentOrAttrs === "string" ? {} : contentOrAttrs;
// now use content and attrs as you please
}
This will be typechecked by the compiler so that if you call title("hi"), it'll know there are no more arguments, and if you call title({ attr: 123 }, "hi"), it'll validate that the first argument is a Record<string, any> and the second argument is a string.