-
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
Add Typed Files/Groups #34
Comments
I like the TypeScript idea! Currently I need to cast all my groups/datasets like this: const attrs = group.attrs as unkown as MyAttrs; |
Love the idea of typing files more strongly! Just wanted to point out that the syntax below is a type assertion in disguise: const file = h5wasm.File<MyHDF5File>(...) This ESLint community rule argues against using this pattern. Perhaps it would be better to keep an explicit type cast? |
Yes, please feel free to make a PR for typed Files/Groups. Also, to answer your other points above:
|
Thank you a lot for the feedback @axelboc! Like you said it is a type assertion, and I was not aware this is discouraged. const file: File<MyType> = h5wasm.File(...)
// or
const file = h5wasm.File(...) as File<MyFile> |
Basically, function isMyFile(file: unknown): file is File<MyFile> {
return /* some condition that is sufficient to say that file is of type `File<MyFile>` */;
}
const file = h5wasm.File(..);
if (isMyFile(file)) {
// file has type // File<MyFile>
} |
I want to contribute a feature I will likely need in the future: Adding types to Files/Groups in order to describe their content. For example, if an HDF5 file has some groups like "data" and "metadata", each containing some datasets, an interface for the File could look like this:
With this, you could "strongly type" any file, and even get type hints in
group.get()
methods. (with typescript Template Literals)First of all, would it okay to add such a feature? If so, I would like to implement it and open a PR. It would, of course, be optional and should not break any existing code.
While working with h5wasm locally, I noticed some things:
datatype_test.mjs
I get an error:As a side-note, I saw in the git history that you thought about switching to esbuild for building h5wasm? Is there any help needed there?
Thank you!
The text was updated successfully, but these errors were encountered: