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

贡献者指南