From a7b04d7cd83e99d9c5fbd948f2e1abe9836ab92d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alice=20R=C3=BChl?= Date: Wed, 17 Dec 2025 20:18:30 +0100 Subject: [PATCH 1/2] fix: use explicit types instead of interface inheritance for hooks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Revert commit 68491419c9d4265c619de5f6ca531e841893fce1 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 --- src/hooks/useCollection.ts | 12 +++++++----- src/hooks/useCollections.ts | 12 +++++++----- src/hooks/useItem.ts | 14 ++++++++------ src/hooks/useStacSearch.ts | 10 ++++++---- src/types/index.d.ts | 23 ----------------------- 5 files changed, 28 insertions(+), 43 deletions(-) diff --git a/src/hooks/useCollection.ts b/src/hooks/useCollection.ts index d3e2398..f2b3af8 100644 --- a/src/hooks/useCollection.ts +++ b/src/hooks/useCollection.ts @@ -1,15 +1,17 @@ -import { useQuery } from '@tanstack/react-query'; -import type { StacHook, StacRefetchFn } from '../types'; +import { useQuery, type QueryObserverResult } from '@tanstack/react-query'; import type { Collection } from '../types/stac'; import { handleStacResponse } from '../utils/handleStacResponse'; import { generateCollectionQueryKey } from '../utils/queryKeys'; import { useStacApiContext } from '../context/useStacApiContext'; import { ApiError } from '../utils/ApiError'; -interface StacCollectionHook extends StacHook { +type StacCollectionHook = { collection?: Collection; - refetch: StacRefetchFn; -} + isLoading: boolean; + isFetching: boolean; + refetch: () => Promise>; + error: ApiError | null; +}; function useCollection(collectionId: string): StacCollectionHook { const { stacApi } = useStacApiContext(); diff --git a/src/hooks/useCollections.ts b/src/hooks/useCollections.ts index 1ac2961..bc4c2cc 100644 --- a/src/hooks/useCollections.ts +++ b/src/hooks/useCollections.ts @@ -1,15 +1,17 @@ -import { useQuery } from '@tanstack/react-query'; -import type { StacHook, StacRefetchFn } from '../types'; +import { useQuery, type QueryObserverResult } from '@tanstack/react-query'; import type { CollectionsResponse } from '../types/stac'; import { handleStacResponse } from '../utils/handleStacResponse'; import { generateCollectionsQueryKey } from '../utils/queryKeys'; import { useStacApiContext } from '../context/useStacApiContext'; import { ApiError } from '../utils/ApiError'; -interface StacCollectionsHook extends StacHook { +type StacCollectionsHook = { collections?: CollectionsResponse; - refetch: StacRefetchFn; -} + refetch: () => Promise>; + isLoading: boolean; + isFetching: boolean; + error: ApiError | null; +}; function useCollections(): StacCollectionsHook { const { stacApi } = useStacApiContext(); diff --git a/src/hooks/useItem.ts b/src/hooks/useItem.ts index 207c428..a8a7bea 100644 --- a/src/hooks/useItem.ts +++ b/src/hooks/useItem.ts @@ -1,17 +1,19 @@ -import { useQuery } from '@tanstack/react-query'; -import type { StacHook, StacRefetchFn } from '../types'; +import { useQuery, type QueryObserverResult } from '@tanstack/react-query'; import type { Item } from '../types/stac'; import { useStacApiContext } from '../context/useStacApiContext'; import { handleStacResponse } from '../utils/handleStacResponse'; import { generateItemQueryKey } from '../utils/queryKeys'; import { ApiError } from '../utils/ApiError'; -interface StacItemHook extends StacHook { +type ItemHook = { item?: Item; - refetch: StacRefetchFn; -} + isLoading: boolean; + isFetching: boolean; + error: ApiError | null; + refetch: () => Promise>; +}; -function useItem(url: string): StacItemHook { +function useItem(url: string): ItemHook { const { stacApi } = useStacApiContext(); const fetchItem = async (): Promise => { diff --git a/src/hooks/useStacSearch.ts b/src/hooks/useStacSearch.ts index 3a4488a..540b94d 100644 --- a/src/hooks/useStacSearch.ts +++ b/src/hooks/useStacSearch.ts @@ -2,7 +2,6 @@ import { useCallback, useState, useMemo, useEffect } from 'react'; import { useQuery, useQueryClient } from '@tanstack/react-query'; import debounce from '../utils/debounce'; import { generateStacSearchQueryKey } from '../utils/queryKeys'; -import type { StacHook } from '../types'; import { handleStacResponse } from '../utils/handleStacResponse'; import type { Link, @@ -17,7 +16,7 @@ import { ApiError } from '../utils/ApiError'; type PaginationHandler = () => void; -interface StacSearchHook extends StacHook { +type StacSearchHook = { ids?: string[]; setIds: (ids?: string[]) => void; bbox?: Bbox; @@ -34,9 +33,12 @@ interface StacSearchHook extends StacHook { setLimit: (limit: number) => void; submit: () => void; results?: SearchResponse; + isLoading: boolean; + isFetching: boolean; + error: ApiError | null; nextPage: PaginationHandler | undefined; previousPage: PaginationHandler | undefined; -} +}; function useStacSearch(): StacSearchHook { const { stacApi } = useStacApiContext(); @@ -212,7 +214,7 @@ function useStacSearch(): StacSearchHook { results, isLoading, isFetching, - error, + error: error ?? null, sortby, setSortby, limit, diff --git a/src/types/index.d.ts b/src/types/index.d.ts index 1d5daa5..c99b252 100644 --- a/src/types/index.d.ts +++ b/src/types/index.d.ts @@ -1,26 +1,3 @@ -import type { QueryObserverResult } from '@tanstack/react-query'; -import { ApiError } from '../utils/ApiError'; - export type GenericObject = { [key: string]: any; // eslint-disable-line @typescript-eslint/no-explicit-any }; - -/** - * 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 = () => Promise>; From b98cdf08d1452a89fb186cc8c22b67dabc17b0ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alice=20R=C3=BChl?= Date: Wed, 17 Dec 2025 20:23:44 +0100 Subject: [PATCH 2/2] 1.0.0-alpha.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 63f8b27..e07806c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@developmentseed/stac-react", - "version": "1.0.0-alpha.1", + "version": "1.0.0-alpha.2", "description": "React components and hooks for building STAC-API front-ends", "repository": "git@github.com:developmentseed/stac-react.git", "authors": [