|
|
|
|
|
by ragnese
1624 days ago
|
|
That's not what soundness means in a type system. Of course untyped input has to be parsed and validated. An unsound type system means that you can write code that compiles, but experiences a runtime error caused specifically by the types (not the values or the business logic conditions) not actually being compatible. The famous example is having an array of a subtype being used as an array of the supertype: function doStuff(animals: Animal[]) {
animals.clear()
animals.push(new Cat())
} const dogs: Dog[] = [new Dog()] doStuff(dogs) dogs[0].bark() // <-- type error In a sound type system, that code would not compile because we know that you can't treat an array of Dog as an array of Animal in general. |
|