-
-
Notifications
You must be signed in to change notification settings - Fork 228
Allow nested metadata #364
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
Allow nested metadata #364
Conversation
d066189
to
4793754
Compare
56b9d1b
to
2458c4e
Compare
b54eee6
to
5d98ab8
Compare
if (isPrimitive(propertyValue) || !isNotArrayLike(propertyValue)) { | ||
throw new Error('Invalid metadata'); | ||
} | ||
anonymizedState[key] = getAnonymizedState(propertyValue, propertyMetadata); |
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 line is where the error is:
Type 'RecursivePartial<S[keyof S]>' is not assignable to type 'S[keyof S] extends (infer U)[] ? RecursivePartial[] : S[keyof S] extends Primitive ? S[keyof S] : RecursivePartial<S[keyof S]>'. ts(2322)
I tried to resolve this by adding type guards to "prove" that the first two conditions were not met.
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.
My guess is that it failed because TypeScript doesn't understand that this is the same S[keyof S] as the other S[keyof S]? That is, these could be referring to two different properties that have different types. But it is the same property here, and I don't know how to tell TypeScript this.
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.
Well, I simplified the RecursivePartial
type locally to test this theory and now I'm less sure. It looks like the Primitive type guard may not be working. I'm not 100% sure though.
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.
I got this working for now with a // ts-ignore
comment 😬
5c033ad
to
a5f390f
Compare
4b499b6
to
ef02ccc
Compare
a5f390f
to
ab74e76
Compare
I've just realized that I forgot to accommodate a fairly common pattern in our controllers: dynamic keys. For example, a lot of our state is keyed by chainId or account or both. I'm going to close this for now and find a more complete solution. |
Allow nested state metadata, so that each metadata property can be applied to properties nested within objects in state.
See the additional tests for examples of what this looks like.