josdejong / josdejong/mathjs

TS regression: Narrowing of MathNodes by type

Open
#2,810 23 comments 0 reactions 0 assignees View on GitHub
bug help wanted typescript
Dominant language
JavaScript
Stars
15.1k
Forks
1.3k
PR merge metrics
No merged PRs in 30d

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:

```ts
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**
- working in v11.2 https://codesandbox.io/s/typescript-playground-export-forked-wnelgb?file=/index.ts
- erroring in v11.3 https://codesandbox.io/s/typescript-playground-export-forked-ke8srr?file=/index.ts

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.