Skip to content

Add support for sigma types #3596

Open
Open
@alexchandel

Description

@alexchandel

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!).

Metadata

Metadata

Assignees

No one assigned

    Labels

    P4featFeature Request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions