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

Update IBeaconConfig#getTypes #2313

Merged
merged 1 commit into from
Mar 31, 2021
Merged

Conversation

wemeetagain
Copy link
Member

Motivation

Currently, we run into an annoying type situation when trying to perform ssz operations on types from a fork known only at runtime.

eg:

const block: allForks.BeaconBlock = ...;

config.getTypes(block.slot).BeaconBlock.hashTreeRoot(block);
//                                                   ^^^^^
// Argument of type 'allForks.BeaconBlock' is not assignable to parameter of type 'phase0.BeaconBlock & altair.BeaconBlock & phase1.BeaconBlock'.

getTypes returns IPhase0SSZTypes | IAltairSSZTypes ....
This means getTypes().BeaconBlock resolves to ContainerType<phase0.BeaconBlock> | ContainerType<altair.BeaconBlock> ...,
which can be further resolved to ContainerType<phase0.BeaconBlock & altair.BeaconBlock ...>.
This intersection type is not what we want, and the way to resolve the issue is with an additional typecast.

Description

The IPhase0SSZTypes | IAltairSSZTypes ... return type has been replaced with IAllForksSSZTypes, which has relevant types replaced with their allForks variant.

This allows for code like the example above to work without additional casting.

@codeclimate
Copy link

codeclimate bot commented Mar 31, 2021

Code Climate has analyzed commit 9f7539f and detected 0 issues on this pull request.

View more on Code Climate.

@wemeetagain wemeetagain merged commit 1cc27c3 into master Mar 31, 2021
@wemeetagain wemeetagain deleted the cayman/all-forks-ssz-types branch March 31, 2021 18:12
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.

None yet

2 participants