josdejong/mathjs

TS regression: Narrowing of MathNodes by type

オープン

#2,810 opened on 2022/10/13

 (23 件のコメント) (0 件のリアクション) (0 人の担当者)JavaScript (1,314 件のフォーク)batch import
bughelp wantedtypescript

Repository metrics

Stars
 (15,065 個のスター)
PR merge metrics
 (PR metrics pending)

説明

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

コントリビューターガイド