josdejong/mathjs

TS regression: Narrowing of MathNodes by type

Open

#2.810 geöffnet am 13. Okt. 2022

Auf GitHub ansehen
 (23 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)JavaScript (1.298 Forks)batch import
bughelp wantedtypescript

Repository-Metriken

Stars
 (13.832 Stars)
PR-Merge-Metriken
 (Keine gemergten PRs in 30 T)

Beschreibung

Describe the bug Prior to v11.3 (not sure how far back, but certainly at least 10), MathNode would be narrowed based on its type property:

const doStuffWithMathNode(node: MathNode) => {
  if (node.type === 'FunctionAssignmentNode) {
    // now TS knows that node is a FunctionAssignmentNode and lets you access associated props
    // like node.params
  }
  // back to being a wider MathNode
}

To Reproduce

Contributor Guide