Can someone give me an example of TypeScript declaration that is not "sound"?
I thought that
"It guarantees that (1) an expression that has a static type T can never evaluate to a value that is not a T, and that (2) evaluation cannot run into unexpected runtime type errors."
Generics are bivariant in TypeScript and so unsound:
class Base {}
class Derived1 extends Base {}
class Derived2 extends Base {}
class Box<T> {
constructor(public value: T) {}
};
var a: Derived1 = new Derived1();
var b: Box<Base> = new Box<Base>(a);
var c: Box<Derived2> = b;
var d: Derived2 = c.value;
TypeScript is structurally typed; there's nothing in your example that suggests that Derived1 and Derived2 have different types, instances of each are the same type.
I thought that
"It guarantees that (1) an expression that has a static type T can never evaluate to a value that is not a T, and that (2) evaluation cannot run into unexpected runtime type errors."
is already supported in TypeScript.