Skip to content

Conversation

@AliceR
Copy link
Member

@AliceR AliceR commented Dec 17, 2025

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 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

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;
};

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could extend with types too like

type StacHook = {
  isLoading: boolean;
  isFetching: boolean;
  error: ApiError | null;
};

type StacCollectionHook = {
refetch: () => Promise<QueryObserverResult<Collection, ApiError>>;
} & StacHook

Copy link

@sandrahoang686 sandrahoang686 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good to know for bundling!

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>>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is possible to keep this pattern and have the types correctly exported. Was there any reason not to?

isLoading,
isFetching,
error,
error: error ?? null,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error is already null. Why is this needed?

@danielfdsilva
Copy link
Member

@sandrahoang686 @AliceR Made a proposal fix in this PR (#45) that doesn't remove the inheritance and reduced duplication.

@AliceR AliceR mentioned this pull request Dec 18, 2025
@AliceR AliceR closed this Dec 18, 2025
@AliceR AliceR deleted the fix/typescript-declarations branch December 18, 2025 19:43
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.

4 participants