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

Add additional fields to OneOfBlock type #2878

Merged
merged 4 commits into from
Jan 30, 2025

Conversation

johnnyomair
Copy link
Collaborator

@johnnyomair johnnyomair commented Dec 4, 2024

We added support for additional fields in the OneOfBlock in #1666. However, the additional fields weren't added to the type.

TODO

  • Changeset

Additional information

First commit adds a test and demonstrates the bug, second commit solves the bug.

@johnnyomair johnnyomair self-assigned this Dec 4, 2024
name,
blockMeta: new Meta(OneOfBlockData),
migrate,
}) as unknown as OneOfBlock<BlockMap, BlockData, BlockInput>;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added the as cast to suppress the following error:

Type 'Block<OneOfBlockDataInterface<BlockMap, BlockDataInterface>, OneOfBlockInputInterface<BlockMap, SimpleBlockInputInterface>>' is not assignable to type 'OneOfBlock<BlockMap, BlockData, BlockInput>'.
  Types of property 'blockDataFactory' are incompatible.
    Type 'BlockDataFactory<OneOfBlockDataInterface<BlockMap, BlockDataInterface>>' is not assignable to type 'BlockDataFactory<OneOfBlockDataInterface<BlockMap, BlockData>>'.
      Type 'OneOfBlockDataInterface<BlockMap, BlockDataInterface>' is not assignable to type 'OneOfBlockDataInterface<BlockMap, BlockData>'.
        Type 'OneOfBlockDataInterface<BlockMap, BlockDataInterface>' is not assignable to type 'BlockData'.
          'OneOfBlockDataInterface<BlockMap, BlockDataInterface>' is assignable to the constraint of type 'BlockData', but 'BlockData' could be instantiated with a different subtype of constraint 'BlockDataInterface'.ts(2322)

I don't think it's possible to fix this without adding such a cast somewhere, so I decided to invest little effort and don't type options, internal classes etc. correctly. Do you think this okay?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not aware enough of how hard it is to have proper typing here, due to my lack of knowledge of the code-base, but I would say this should really be avoided 😅

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean? Avoid the as cast?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this can be achieved when using generics though

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just checked out the code for it and I'm not familiar with the code here either but I agree with Obi. Even if I don't like the cast, I haven't come up with anything better here, if that's even possible. I could only imagine that Niko will come up with something else here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Reaw I've invested some more time and moved the as casts further into the factory: 25f396f. I don't know how the remaining errors could be fixed, and I don't want to invest more time into it, since it's perfectly fine to have as casts in the library. Feel free to give it a shot though.

raphaelblum
raphaelblum previously approved these changes Dec 12, 2024
@vivid-planet vivid-planet deleted a comment from sonarqubecloud bot Jan 30, 2025
@johnnyomair johnnyomair merged commit 7e7a4aa into main Jan 30, 2025
12 checks passed
@johnnyomair johnnyomair deleted the COM-827-create-one-block-additional-fields branch January 30, 2025 08:08
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.

4 participants