Skip to content

Commit 5859d09

Browse files
authored
fix: revert ObservableStatus to a strict (non-union) type (#750)
* test: type-check the test suite in CI to catch type regressions Adds tsconfig.test.json (type-checks src + test) and runs it in the type-check workflow. The test suite already exercises hooks the way consumers do (reading .data off results), so a breaking change to the public types now fails CI at compile time. Also fixes pre-existing test-only type issues surfaced by turning the check on: unused imports, node globals (require/global/Buffer) via the node types, and a FunctionComponent children prop annotation. * fix: revert ObservableStatus to a strict (non-union) type 4.2.4 shipped ObservableStatus<T> as a discriminated union (data is T | undefined unless narrowed on status), which broke the documented pattern of reading .data directly across every data hook. Revert the type to the previous strict shape (data: T) so this ships as a patch. The genuinely-optional cases stay correctly typed at the hook level (useFirestoreDocData/DocDataOnce return T | undefined, useUser returns User | null, useDatabaseListData returns T[] | null), which is where the undefined belongs rather than on ObservableStatus itself. The internal SuspenseSubject status builders keep an as-cast since the in-flight loading value is internally T | undefined. * docs: regenerate reference docs for ObservableStatus type change ObservableStatus is now an interface again rather than a discriminated union type-alias, so the generated reference docs drop the per-status sub-interface pages and retarget links from type-aliases/ to interfaces/. * test: strengthen the type guard with typed object-data and doc-data reads Per review: the guard did not exercise useDatabaseObjectData, and the existing useFirestoreDocData tests use <any> so their .data reads are untyped. Add a useDatabaseObjectData test with a typed .data read (data is T, so it fails to compile if ObservableStatus regresses to a union) and a concretely-typed useFirestoreDocData read.
1 parent 43dc25a commit 5859d09

35 files changed

Lines changed: 109 additions & 361 deletions

‎.github/workflows/test.yaml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ jobs:
100100
run: npm install --no-save react@${{ matrix.react }} react-dom@${{ matrix.react }} @types/react@${{ matrix.react }} @types/react-dom@${{ matrix.react }}
101101
- name: Type check
102102
run: npx tsc --noEmit
103+
- name: Type check tests
104+
run: npx tsc --noEmit -p tsconfig.test.json
103105
publish:
104106
runs-on: ubuntu-latest
105107
name: Publish (NPM)

‎docs/reference/README.md‎

Lines changed: 1 addition & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎docs/reference/functions/useCallableFunctionResponse.md‎

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎docs/reference/functions/useDatabaseList.md‎

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎docs/reference/functions/useDatabaseListData.md‎

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎docs/reference/functions/useDatabaseObject.md‎

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎docs/reference/functions/useDatabaseObjectData.md‎

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎docs/reference/functions/useFirestoreCollection.md‎

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎docs/reference/functions/useFirestoreCollectionData.md‎

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎docs/reference/functions/useFirestoreDoc.md‎

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)