mobxjs / mobx-state-tree

Full-featured reactive state management without the boilerplate
https://mobx-state-tree.js.org/
MIT License
6.94k stars 640 forks source link

Improve typing for isXYZType narrowing functions #2190

Closed thegedge closed 2 months ago

thegedge commented 3 months ago

What does this PR do and why?

Fixes #2184

Our narrowing functions, like isLateType, weren't properly narrowing things to the expected type. This PR fixes that by writing them like the typical narrowing function in TS:

function isXYZ(v: unknown): v is XYZ { … }

Steps to validate locally

Given this is just a change to types, one can run the bun typecheck and bun test __tests__/core/type-system.test.ts (where I've added a new test).

thegedge commented 3 months ago

cc @coolsoftwaretyler

coolsoftwaretyler commented 3 months ago

Phenomenal! You are really on a roll. Thanks for all the help. Will review and probably merge/ship this weekend or early in the week.

coolsoftwaretyler commented 2 months ago

@thegedge - looks great to me! I rebased to fix up some of the conflicts from https://github.com/mobxjs/mobx-state-tree/pull/2189. Will merge this in and release as a patch as well.