Fix: use explicit types instead of interface inheritance for hooks#44
Closed
Fix: use explicit types instead of interface inheritance for hooks#44
Conversation
Revert commit 6849141 Replace interface inheritance pattern with explicit type definitions to ensure TypeScript declarations bundle correctly. The StacHook base interface was causing vite-plugin-dts to generate incomplete type declarations where inherited properties (isLoading, isFetching, error) were not visible to library consumers. Changes: - Remove StacHook interface and StacRefetchFn<T> from src/types/index.d.ts - Convert all hook return types from interface inheritance to explicit types - Add all properties directly to each hook type definition - Fix error type coercion in useStacSearch (undefined → null) - Fixes "Property 'isLoading' does not exist" errors in consuming projects
| isFetching: boolean; | ||
| refetch: () => Promise<QueryObserverResult<Collection, ApiError>>; | ||
| error: ApiError | null; | ||
| }; |
There was a problem hiding this comment.
could extend with types too like
type StacHook = {
isLoading: boolean;
isFetching: boolean;
error: ApiError | null;
};
type StacCollectionHook = {
refetch: () => Promise<QueryObserverResult<Collection, ApiError>>;
} & StacHook
danielfdsilva
requested changes
Dec 18, 2025
Comment on lines
-7
to
-26
|
|
||
| /** | ||
| * Base interface for all STAC hooks providing common loading state and error handling. | ||
| * All data-fetching hooks (useCollection, useCollections, useItem, useStacSearch) | ||
| * extend this interface with their specific data and refetch signatures. | ||
| */ | ||
| export interface StacHook { | ||
| /** True during initial data fetch (no cached data available) */ | ||
| isLoading: boolean; | ||
| /** True during any fetch operation (including background refetches) */ | ||
| isFetching: boolean; | ||
| /** Error information if the last request was unsuccessful */ | ||
| error: ApiError | null; | ||
| } | ||
|
|
||
| /** | ||
| * Generic refetch function type for STAC hooks. | ||
| * Returns a Promise with the query result including data and error information. | ||
| */ | ||
| export type StacRefetchFn<T> = () => Promise<QueryObserverResult<T, ApiError>>; |
Member
There was a problem hiding this comment.
It is possible to keep this pattern and have the types correctly exported. Was there any reason not to?
danielfdsilva
requested changes
Dec 18, 2025
| isLoading, | ||
| isFetching, | ||
| error, | ||
| error: error ?? null, |
Member
There was a problem hiding this comment.
The error is already null. Why is this needed?
Member
|
@sandrahoang686 @AliceR Made a proposal fix in this PR (#45) that doesn't remove the inheritance and reduced duplication. |
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Revert commit 6849141
Replace interface inheritance pattern with explicit type definitions to ensure TypeScript declarations bundle correctly. The StacHook base interface was causing vite-plugin-dts to generate incomplete type declarations where inherited properties (isLoading, isFetching, error) were not visible to library consumers.
Changes:
Fixes "Property 'isLoading' does not exist" errors in consuming projects