-
Notifications
You must be signed in to change notification settings - Fork 643
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
Broken model types in 6.0.0 version #2186
Comments
Thanks for the bug report @dfilatov! Sorry for the inconvenience. I will look into this soon. |
Hi @dfilatov - what TypeScript version are you using? I'm having trouble reproducing. Here's a CodeSandbox without errors: https://codesandbox.io/p/sandbox/issue-2186-reproduction-dgy9g3 Version 6.0.0 upgraded TypeScript to |
5.4.5 |
Oh nice. Must have been a bug on CodeSandbox. Will continue investigating! |
I ran git bisect on the reproduction code you provided and it identified 46334b6 as the commit that introduced the error. I wonder if Will keep investigating! |
Ok, looks like the issue is with @dfilatov - are you only encountering this issue specifically when you create a base model with no properties? I want to figure out if this is happening because empty models are a special case or if there's a bigger problem with the Let me know! |
yep, looks like it's happened with base models without own props (but with own actions/views) |
Very helpful! I think we just need to figure out some way to carve out the types to accommodate a model like that. As a stopgap while we figure it out, I might suggest adding some kind of placeholder property in that model definition to clear the error if you don't want to ts-ignore/ts-expect-error |
The root of the problem is, I believe, here: export type ModelCreationType2<P extends ModelProperties, CustomC> = keyof P extends never
? // When there are no props, we want to prevent passing in any object. We have two objects we want to allow:
// 1. The empty object
// 2. An instance of this model
//
// The `IStateTreeNode` interface allows both. For (1), these props are optional so an empty object is allowed.
// For (2), an instance will contain these two props, including the "secret" `$stateTreeNodeType` prop. TypeScript's
// excess property checking will then ensure no other props are passed in.
IStateTreeNode
: _CustomOrOther<CustomC, ModelCreationType<ExtractCFromProps<P>>> Introduced here: 46334b6#diff-8ce65433bb1651566fa2253bfc8167953b5871ef77ed073d1d47d0e4876fabdcR139 If we go back to the old definition of I brought this up in the maintainers' Discord channel because I'm not sure how to reconcile the old behavior with the new. If anyone out there has a good TypeScript idea, let me know. |
There is one workaround that exists today. If you use the
Here's no red lines in VS Code: I would say this is actually more correct anyway, as |
I suppose it isn't exactly correct to say that this is an Instance, since it's an extension of the definition. Still, this makes me think we can maintain the TypeScript changes from 6.0.0 and make another type alias available that you can use to opt into the second clause of the conditional type. I will think some more on it but this feels like a viable path forward. |
💯 I do think this should be permitted. I'll try to get this fixed sometime this weekend and make sure we expand the test suite for types. Thanks for the report, @dfilatov! |
Should be fixed in #2189, which I'll merge and release sometime this weekend or early next week. |
Just merged! This will be out in a patch release soon. |
Great, thank you! |
Bug report
Sandbox link or minimal reproduction code
Describe the expected behavior
No type errors
Describe the observed behavior
It has been broken in 6.0.0 version. It works in 5.4.1 version as expected.
The text was updated successfully, but these errors were encountered: