josdejong/mathjs

TS regression: Narrowing of MathNodes by type

開放

#2,810 建立於 2022年10月13日

 (23 則留言) (0 個反應) (0 位負責人)JavaScript (1,314 個分叉)batch import
bughelp wantedtypescript

倉庫指標

星標
 (15,065 顆星)
PR 合併指標
 (PR 指標待抓取)

描述

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

貢獻者指南