josdejong/mathjs

TS regression: Narrowing of MathNodes by type

Open

#2 810 ouverte le 13 oct. 2022

Voir sur GitHub
 (23 commentaires) (0 réactions) (0 assignés)JavaScript (1 298 forks)batch import
bughelp wantedtypescript

Métriques du dépôt

Stars
 (13 832 stars)
Métriques de merge PR
 (Aucune PR mergée en 30 j)

Description

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

Guide contributeur