|
|
|
|
|
by afiori
697 days ago
|
|
The key factor is that typescript is not a language, it is a notation system for a completely independent language. The purpose of typescript is usefully type as much javascript as possible, to do both this and have a sound type system it would require to change javascript. |
|
A prime example is that if you index into an array of type `T[]`, JS semantics mean the value you get back could be undefined as well as a `T`. So to describe existing JS semantics in a sound type system, the type would have to be `T | undefined`, which would be a big pain. Alternatively you could make the type `T` and have that be sound, but only if you make the runtime semantics be that an out-of-bounds access throws instead of returning undefined.