-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Bug: using nested signalStoreFeature causes an error when applying mapped-types over generics in withComputed #4599
Comments
Ouch, once I saw your name, I knew that one isn't going to be easy ;) Thanks for the stackblitz. I have no idea. I tried out various combinations. One could investigate setting the types for Hopefully someone else from the team can help you out here. |
I found a workaround. When adding New Stackblitz https://stackblitz.com/edit/github-4qdexu-yasxch?file=src%2Fmain.ts,src%2Findex.html type DictOverMappedGenericType<Key extends string> =
RecordFoo &
MappedTypeOverGenericUnions<Key> & // This generic type within a mapped-typed led to an error but the magic line below was able to fix the error
{ [key: string]: Signal<unknown> }; // 🪄 this is the magic line |
Congratulations on finding the fix yourself! 🎉
🤔 It’s hard to say. Especially with signalStoreFeature, we’re really pushing the boundaries of TypeScript. This might be worth considering for the documentation, though there’s a concern that documenting it could lead to overuse. I see your example as a highly advanced use case. For scenarios like this, it might be best for developers like you to open an issue when encountering similar challenges. That way, we can track these edge cases and hopefully remember approaches like yours in the future. |
@SerkanSipahi, as discussed above, I’ll go ahead and close this for now. If anything else comes up, feel free to reopen it. Thanks again for providing the solution! |
I want to say something in conclusion. For the average developer this can be seen as an advanced use case but for a library developer, this case is common. Basically, I just tried to pass a generic type through several nested signalStoreFeature functions. Nothing special actually. It can look complicated or complex but it only looks like this because it is in the context of signalStoreFeature. It was just a small snapshot of my current work. |
@SerkanSipahi Yes, we might want to add a section for library developers that covers this and other cases. |
Which @ngrx/* package(s) are the source of the bug?
signals
Minimal reproduction of the bug/regression with instructions
https://stackblitz.com/edit/github-4qdexu-whtv54?file=src%2Fmain.ts,src%2Findex.html (see main.ts)
Current behavior:
Nested signalStoreFeatures are not a concern, such as using signalStoreFeature within signalStoreFeature. However, an error occurs in signalStoreFeatureParent when using withFeatureStoreChild and MappedTypeOverGenericUnions along with withState(...) or withEntities(...) in signalStoreFeatureParent, see
return () => signalStoreFeature(withFeatureStoreChild(keys));
, see minimal stackblitz reproduction or below the code example.Some observations:
withState
andwithEntities
andMappedTypeOverGenericUnions<Key>
is present the error disappearsMappedTypeOverGenericUnions<Key>
withState
andwithEntities
are preserved andMappedTypeOverStaticUnions
is used then there is no error.Example:
Expected behavior
My expectation is that the use of
MappedTypeOverGenericUnions<Key>
does not lead to an error inwithFeatureStoreParent
. Mapped types in general do not lead to an error, seeMappedTypeOverStaticUnions
inwithFeatureStoreChild
.Versions of NgRx, Angular, Node, affected browser(s) and operating system(s)
@ngrx/signals 18.1.0
Other information
I assume that this is an error and must be rectified. Is there a workaround in the meantime?
I would be willing to submit a PR to fix this issue
The text was updated successfully, but these errors were encountered: