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

Fix Value<D> and export getExportURL function type #1249

Merged
merged 2 commits into from
Nov 2, 2022
Merged

Conversation

axelboc
Copy link
Contributor

@axelboc axelboc commented Oct 28, 2022

Partial fix for #1063

There was a problem with the Value<D> type. In advanced cases, like the one identified by @bmaranville, the shape and dtype of the Dataset generic was not properly inferred.

getExportURL is only called with array-shaped datasets (Dataset<ArrayShape>), but Value<D> was not being narrowed down at all. Now, Value<D> is properly narrowed down to unknown[] | TypedArray (if we go down to the barest types).

getExportURL={(format, dataset, selection, value) => async () => {
  value.forEach((val) => { /* ... */ }); // `forEach` now works because it is available on both arrays and typed arrays
}}

I'm also exporting the type of the getExportURL function in @h5web/app so one can extract the function outside of the JSX:

const getExportURL: GetExportURL = (format, dataset, selection, value) => { ... };

I'm usually not a fan of function expressions, but in this case, replicating the signature would require exporting a lot of types and would be prone to mistakes. Indeed, with a function declaration, given the permissive nature of TS, consumers may not end up typing the function as strictly as they could and therefore struggle to implement it.

@axelboc axelboc merged commit ff35ff7 into main Nov 2, 2022
@axelboc axelboc deleted the fix-value-type branch November 2, 2022 09:27
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

3 participants