Skip to content

Commit

Permalink
Define some return types explicitly to help TypeScript compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
axelboc committed Sep 4, 2024
1 parent 717efad commit 7045c0f
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions src/hdf5_hl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ enum OBJECT_TYPE {
REGION_REFERENCE = 'RegionReference',
}

export type getReturnTypes = Dataset | Group | BrokenSoftLink | ExternalLink | Datatype | Reference | RegionReference;
export type Entity = Dataset | Group | BrokenSoftLink | ExternalLink | Datatype | Reference | RegionReference;

export class BrokenSoftLink {
// only used for broken links...
Expand Down Expand Up @@ -586,7 +586,7 @@ abstract class HasAttrs {

get attrs() {
let attr_names = Module.get_attribute_names(this.file_id, this.path) as string[];
let attrs: {[key: string]: Attribute} = {};
let attrs: Record<string, Attribute> = {};
const { file_id, path } = this;
for (let name of attr_names) {
Object.defineProperty(attrs, name, {
Expand All @@ -595,7 +595,6 @@ abstract class HasAttrs {
});
}
return attrs;

}

get root() {
Expand Down Expand Up @@ -665,7 +664,7 @@ abstract class HasAttrs {
return new Reference(ref_data);
}

dereference(ref: Reference | RegionReference): DatasetRegion | getReturnTypes | null {
dereference(ref: Reference | RegionReference): DatasetRegion | Entity | null {
const is_region = (ref instanceof RegionReference);
const name = Module.get_referenced_name(this.file_id, ref.ref_data, !is_region);
const target = this.root.get(name);
Expand Down Expand Up @@ -694,22 +693,22 @@ export class Group extends HasAttrs {
this.type = OBJECT_TYPE.GROUP;
}

keys(): Array<string> {
return Module.get_names(this.file_id, this.path, false) as string[];
keys(): string[] {
return Module.get_names(this.file_id, this.path, false);
}

* values() {
* values(): Generator<Entity | null, void, never> {
for (let name of this.keys()) {
yield this.get(name);
}
return
return;
}

* items() {
* items(): Generator<[string, Entity | null], void, never> {
for (let name of this.keys()) {
yield [name, this.get(name)];
}
return
return;
}

get_type(obj_path: string) {
Expand All @@ -724,7 +723,7 @@ export class Group extends HasAttrs {
return Module.get_external_link(this.file_id, obj_path);
}

get(obj_name: string): getReturnTypes | null {
get(obj_name: string): Entity | null {
let fullpath = (/^\//.test(obj_name)) ? obj_name : this.path + "/" + obj_name;
fullpath = normalizePath(fullpath);

Expand Down

0 comments on commit 7045c0f

Please sign in to comment.