-
Notifications
You must be signed in to change notification settings - Fork 23
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 support for complex dataset values in h5wasm #1111
Conversation
export function convertMetadataToDType(metadata: NumericMetadata): NumericType; | ||
export function convertMetadataToDType(metadata: Metadata): DType; | ||
export function convertMetadataToDType(metadata: Metadata): DType { | ||
if (isIntegerMetadata(metadata)) { |
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 reworked the switch to use dedicated guards to allow TS to infer the typing of metadata.
It allows more specific destructurings for Integer, Float and String but the important part is that compound metadata is correctly inferred.
if (nmembers === 2 && members[0].name === 'r' && members[1].name === 'i') { | ||
const [realTypeMetadata, imagTypeMetadata] = members; | ||
assertNumericMetadata(realTypeMetadata); | ||
assertNumericMetadata(imagTypeMetadata); |
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.
Thanks to this assertion and the overload of convertMetadataToDType
above, TS knows that converting this will yield a NumericType
removing the need to assert after conversion.
class: DTypeClass.Compound, | ||
fields: Object.fromEntries( | ||
members.map((member) => [member.name, convertMetadataToDType(member)]) | ||
), |
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.
Following our line of work in HSDS, we try to be as specific as possible even if it is not complex and that we don't provide visualizations for such types.
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.
Nicely done 👍
Thanks to v0.4.2 of h5wasm
I still have some issues with boolean which is why it is not included in this PR