josdejong/mathjs

TS regression: Narrowing of MathNodes by type

Open

#2810 aperta il 13 ott 2022

Vedi su GitHub
 (23 commenti) (0 reazioni) (0 assegnatari)JavaScript (1298 fork)batch import
bughelp wantedtypescript

Metriche repository

Star
 (13.832 star)
Metriche merge PR
 (Nessuna PR mergiata in 30 g)

Descrizione

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

Guida contributor