Skip to content
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

Gudahtt
Copy link
Member

@Gudahtt Gudahtt commented Feb 25, 2021

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.

@Gudahtt Gudahtt force-pushed the add-base-controller-schema-nested-metadata branch from d066189 to 4793754 Compare February 25, 2021 05:16
@Gudahtt Gudahtt force-pushed the add-base-controller-schema-nested-metadata branch 2 times, most recently from b54eee6 to 5d98ab8 Compare February 25, 2021 05:20
src/BaseControllerV2.ts Outdated Show resolved Hide resolved
if (isPrimitive(propertyValue) || !isNotArrayLike(propertyValue)) {
throw new Error('Invalid metadata');
}
anonymizedState[key] = getAnonymizedState(propertyValue, propertyMetadata);
Copy link
Member Author

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.

Copy link
Member Author

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.

Copy link
Member Author

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.

Copy link
Member Author

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 😬

@Gudahtt Gudahtt force-pushed the add-base-controller-schema-nested-metadata branch 2 times, most recently from 5c033ad to a5f390f Compare February 25, 2021 14:08
@Gudahtt Gudahtt marked this pull request as ready for review February 25, 2021 17:11
@Gudahtt Gudahtt requested a review from a team as a code owner February 25, 2021 17:11
@Gudahtt Gudahtt force-pushed the add-base-controller-schema-nested-metadata branch from a5f390f to ab74e76 Compare February 25, 2021 19:38
@Gudahtt
Copy link
Member Author

Gudahtt commented Feb 26, 2021

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.

@Gudahtt Gudahtt closed this Feb 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant