-
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
New type errors in Model.create with version 7.0.0 #2233
Comments
Let me take a shot at fixing the mess I keep creating 😂 🙈 |
Haha, it's our mess, my friend. The typescript version makes a ton of sense here, because I don't think I've seen this on apps I'm working on with MST 7 and TypeScript 5. I haven't thought enough about TS version requirements yet. If there's an easy path for supporting an older version, it's worth it. But if you find it's taking too long to fix or is gonna spur more headaches, I think we can evaluate what a good TS target is. We haven't put thought into that for a while here, so it's worth consideration. |
👍 sounds good. I'll pick at it, see if I can't make something work in both versions. I'll see if I can set up some kind of TS matrix to test older versions. I don't think it's worth going lower than 4, and I'll see the lowest minor version of 4 I can easily get working. Once we figure out the min version, what do you think about using peer dependencies (and {
"peerDependencies": {
"typescript": ">=4.x.y"
},
"peerDependenciesMeta": {
"typescript": {
"optional": true
}
}
} That way people will know any older version of TS is probably not gonna work. Looks like it was introduced in a later minor version of npm 6. That's more than 4 years old, so I'd say reasonable to expect at least that, eh? |
Yeah I feel good about that as a fallback! |
It's a little more than the typescript version. I'm using 5.7.2 and getting typing errors. I thought I was crazy for a bit because I could have sworn that Model.create() used to infer the type properly Here's what I am seeing:
Model.create does not properly type the create() method of the ModelType. This goes for maps, arrays, and models.
As stated above everything works normally with MST 6. The big difference is the use of ts-essentials in v7. I removed teh From this:
to this:
Everything worked as expected here with latest versions. Then I installed ts-essentials as a dependency while I was messing around with the ExcludeReadonly and the use of WritabelKeys from ts-essentials and noticed everything worked as expected. It's probably just not including the ts-essentials library when building declarations or something simple for someone who has more patience than I do with TS. hth. |
@tm-3, that's super helpful, thank you! I'm about to be on a cross country move, but by early 2025 I can look deeper into this and see what else we can do to fix things. Sorry for the inconvenience! |
not a problem at all. Adding ts-essentials as a dependency works for now. If I get extra time I'll dig a bit deeper, but probably not until after Christmas. Safe travels! |
Appreciate the digging deeper, @tm-3. I've been on vacation and now super busy prepping for the holidays, but I should have some time to look at this before the new year. It's too bad that all of these changes have caused regressions, but we can capture all of these in typechecking tests and prevent it from happening again 🙌 |
Bug report
Originally reported in the v7.0.0 discussion post: #2224 (comment)
Sandbox link or minimal reproduction code
Here is a CodeSandbox reproduction.
On v6.0.1, we get a type error correctly: https://codesandbox.io/p/sandbox/naughty-bassi-forked-39c7cz?file=%2Fsrc%2Findex.ts&workspaceId=ws_QGa4cGacuoY7BgaNFKGDj8
On v7.0.0, MST will fail at runtime, but TypeScript does not warn us about that problem: https://codesandbox.io/p/sandbox/gv3tn2?file=%2Fsrc%2Findex.ts
Describe the expected behavior
We should receive type errors on the
a
property when passing a string to atypes.number
.Describe the observed behavior
No type error in version 7.0.0
The text was updated successfully, but these errors were encountered: