23 Sep
2020
23 Sep
'20
4:28 p.m.
That depends on how you define "intersection type". If you are using the classic definition from type theory, then yes, use of an intersection type is unsound. TypeScript, Scala and other newer languages define "intersection type" a bit differently. https://www.typescriptlang.org/docs/handbook/unions-and-intersections.html#i.... They treat an intersection as a new type that combines the subtypes into one — i.e. it has all the members of all of the subtypes — to support ad hoc polymorphism. That's safe, but it is meaningful only for structural types. And it doesn't really apply to the AnyOf discussion.