>[...] suddenly the function returns a number array instead of a string and the compiler will be just fine with it.
The type checker is quite forgiving, but that does not sound like something it would just be fine with?
The TS type system is not sound which has obvious tradeoffs. I prefer it over Rust for most things because Rust feels like a Comic-book-guy type person looking over my shoulder going "Akshually, you didn't tell me what the lifetime of this string is", even if it is trivially obvious. I acknowledge that there are situations where that is very valuable but in my opinion it's not generally superior.