google / google/closure-compiler
Add support for sigma types
- Dominant language
- JavaScript
- Stars
- 7.7k
- Forks
- 1.2k
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 6
Description
A [sigma type](https://en.wikipedia.org/wiki/Dependent_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`.
```js
/**
* @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!).
Contributor guide
Assessment
This issue has not been assessed yet.