-
Notifications
You must be signed in to change notification settings - Fork 642
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bump typescript from 3.9.10 to 5.3.3 #2146
Conversation
@@ -16,7 +16,7 @@ import { | |||
joinJsonPath | |||
} from "../../src" | |||
|
|||
function testPatches<C, S, T>( | |||
function testPatches<C, S, T extends object>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be correct. Without it, getSnapshot
is complaining:
Argument of type 'STNValue<T, IType<C, S, T>>' is not assignable to parameter of type 'IStateTreeNode<IType<any, unknown, any>>'.
Type 'T | (T & IStateTreeNode<IType<C, S, T>>)' is not assignable to type 'IStateTreeNode<IType<any, unknown, any>>'.
Type 'T' is not assignable to type 'IStateTreeNode<IType<any, unknown, any>>'.ts(2345)
jsonpatch.test.ts(19, 28): This type parameter might need an `extends IStateTreeNode<IType<any, unknown, any>>` constraint.
The problem is that IType["create"]
returns an STNValue
, and without any constraints you can see that it will be (T & IStateTreeNode<IT>) | T
, and getSnapshot
needs an IStateTreeNode<IT>
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the note! This makes sense. I think we were hitting that over in #2103
__tests__/core/type-system.test.ts
Outdated
@@ -22,6 +22,10 @@ import { | |||
} from "../../src" | |||
import { $nonEmptyObject } from "../../src/internal" | |||
|
|||
const assertTypesEqual = <T, U>(t: T, u: Exact<T, U> extends never ? T : U): [T, U] => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exact<T, U> extends never ? T : U
means "when not the exact same type, use the type of the first arg otherwise the type of the second arg". Making it the first arg's type when not exact gives us a typechecking error directly from TS:
TODO: Verify this is still okay if !Exact<T, U>
but T extends U
Okay, this needs some work because assertTypesEqual(_ as { a: 1 }, _ as { a: 1; b: 2 })
doesn't fail typechecking. Will fix!
Fixed. I've added a "checker" type to show you which keys aren't matching exactly:
Would have loved to have something like "Mismatched properties: a, b", but unfortunate a union type + template string literals don't work that way 😢
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Phenomenal. This is what I really needed when I was first trying to debug the old spec.ts
failures. Thank you!
Once again, @thegedge - thank you very much for taking this on. It will un-block us on #2103, and I hope it will also lead to better typings in general. I'll make sure we stay up to date with TypeScript changes on a more regular cadence from here on out. I'm going to merge this in. I have a few other PRs I'd like to merge this week alongside it, so I'll ship some pre-releases throughout to make sure the TS changes are all good for our downstream users. |
What does this PR do and why?
Upgrade
mobx-state-tree
to the latest version of typescript (3.9 -> 5.3).We were really far behind and missing out on all of the performance improvements and bug fixes, along with features that will allow writing better types for MST (e.g., variadic tuple types for
types.union
to avoid anIAnyType
when 10 or more types unioned).Steps to validate locally
Leaning on existing tests for build correctness, and other than that I've corrected a few failing typechecks.
The
include
config intsconfig.json
has also been updated to ensure typechecking in__tests__
happens, and I've added atypecheck
command topackage.json
to be able to run just a typecheck on the codebase. I iterated on those until everything passed.