-
Notifications
You must be signed in to change notification settings - Fork 12
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
Fix calling get_attribute_names
on committed datatype
#84
Conversation
#83 is merged |
0dd3284
to
792da15
Compare
@axelboc I don't mean to hijack your PR but this seemed like a logical place to also make the changes to the Datatype class, supporting attributes. Do the types look ok? |
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.
Please be my guest! 😊 Looks like I completely missed extending from HasAttrs
, thanks.
src/hdf5_hl.ts
Outdated
dereference(ref: Reference | RegionReference): DatasetRegion | getReturnTypes | null { | ||
const is_region = (ref instanceof RegionReference); |
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.
Might be cleaner to override this method in the RegionReference
class to avoid returning DatasetRegion
when invoking this method on other kinds of objects.
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.
RegionReference
doesn't extend HasAttrs
, so what I suggested was not possible. Instead, I added signature overrides to the dereference
method so that if one passes a RegionReference
, the return type is DatasetRegion
:
dereference(ref: RegionReference): DatasetRegion;
dereference(ref: Reference | RegionReference): DatasetRegion | getReturnTypes | null;
src/hdf5_hl.ts
Outdated
@@ -504,6 +504,8 @@ enum OBJECT_TYPE { | |||
REGION_REFERENCE = 'RegionReference', | |||
} | |||
|
|||
export type getReturnTypes = Dataset | Group | BrokenSoftLink | ExternalLink | Datatype | Reference | RegionReference; |
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.
Perhaps the term Entity
would be more suited? In H5Web, Entity
is the base interface, and ProvidedEntity
is the union of all entity interfaces that extend Entity
, but since the bare term "entity" doesn't seem to be used yet in h5wasm, I see no problem using it. Otherwise, maybe ChildEntity
?
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 used Entity
, but feel free to rename. I ruled out Object
since it's already used by TypeScript.
src/hdf5_hl.d.ts
Outdated
values(): Generator<BrokenSoftLink | ExternalLink | Datatype | Group | Dataset | null, void, unknown>; | ||
items(): Generator<(string | BrokenSoftLink | ExternalLink | Datatype | Group | Dataset | null)[], void, unknown>; | ||
values(): Generator<getReturnTypes | null, void, unknown>; | ||
items(): Generator<(string | Reference | Dataset | Group | BrokenSoftLink | ExternalLink | Datatype | null)[], void, unknown>; |
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.
Returning a tuple should work and be more accurate:
items(): Generator<(string | Reference | Dataset | Group | BrokenSoftLink | ExternalLink | Datatype | null)[], void, unknown>; | |
items(): Generator<[string, getReturnTypes | null], void, unknown>; |
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 part is generated by the typescript compiler directly, not by me
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.
Oh right, because you changed the return type of Group#get
. I think we can "fix" it by defining the return type explicitly on Group#items
.
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.
Done
7045c0f
to
be0920e
Compare
e38f297
to
a97e5f3
Compare
When I run |
Apologies, I was on a Windows machine. I've added an |
Addresses #80 (comment)
Tested locally with: