Short version: just use io-ts or tsoa to help check for this at runtime.
Long version: You make a very good point however there are no programming languages that check the length or existence of a string at compile time. So in Java, modern C#, Kotlin, etc a string can still be empty. However, TypeScript and Kotlin can at least check for null and undefined unlike Java and older C#.
Think of this like an array of characters instead of a word. In fact, that’s how C++ represents strings (from what I can remember).
So since the length of an array is always a variable size the language can’t determine if the string is empty at compile time. But if you use a runtime validation library at your io layer or your API layer then you can clean the data before it gets too far into the code.
Short version: just use io-ts or tsoa to help check for this at runtime.
Long version: You make a very good point however there are no programming languages that check the length or existence of a string at compile time. So in Java, modern C#, Kotlin, etc a string can still be empty. However, TypeScript and Kotlin can at least check for null and undefined unlike Java and older C#.
Think of this like an array of characters instead of a word. In fact, that’s how C++ represents strings (from what I can remember).
So since the length of an array is always a variable size the language can’t determine if the string is empty at compile time. But if you use a runtime validation library at your io layer or your API layer then you can clean the data before it gets too far into the code.
Thanks! That's a good point that no other language handles this case either. I'll look into io-ts and tsoa.