Open
Description
A sigma type or "dependent pair" is a type determined by the value of another variable. A common example is C++ templates with int
parameters.
For example, consider the contrived case below, except where b
is a number
if a == Result.PRIME
, but an Array
if and only if a == Result.COMPOSITE
.
/**
* @enum
*/
Result = {
PRIME: 1,
COMPOSITE: 0
}
/**
* @param {Result} a
* @param {number|Array<[number, number]>}
*/
function foo(a, b) {
// ...
}
At the moment, this cannot be annotated, and it requires manual testing and /** @type {SomeClass} */
casting. But the compiler has the ability to reason about valid values, and validate these checks for you (free of human error!).