Fix Value<D>
and export getExportURL
function type
#1249
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 theDataset
generic was not properly inferred.getExportURL
is only called with array-shaped datasets (Dataset<ArrayShape>
), butValue<D>
was not being narrowed down at all. Now,Value<D>
is properly narrowed down tounknown[] | TypedArray
(if we go down to the barest types).I'm also exporting the type of the
getExportURL
function in@h5web/app
so one can extract the function outside of the JSX: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.