"Full type safety would require a lot of runtime checks injected into the final JavaScript"
Why would this be the case?
Why would this be the case?
Many type-safe languages throw an exception if you attempt to access an element in an array that is out of bounds but javascript just returns undefined.
Typescript ignores the fact that accessing an arbitrary element of an array could return undefined. If it did not ignore this fact then it would force you to deal with the potential undefined value retrieved from any array access (i.e you'd need to write a runtime check)
In some instances it makes sense to use a special NonEmptyList type that guarantees there is always at least one element, so you don't need to check.