-
Notifications
You must be signed in to change notification settings - Fork 404
fix: tighten ReactFireOptions generic types, remove T | any widening #740
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| src/*.type-test.ts |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| /** | ||
| * Type-level regression tests for ReactFireOptions<T> generic constraints. | ||
| * Checked by `tsc --noEmit` in CI. No runtime behavior — not bundled. | ||
| */ | ||
| import type { ReactFireOptions } from './index'; | ||
|
|
||
| // ---- initialData must match T ---- | ||
|
|
||
| void ((): ReactFireOptions<string> => ({ initialData: 'hello' }))(); | ||
| void ((): ReactFireOptions<number> => ({ initialData: 42 }))(); | ||
|
|
||
| // @ts-expect-error initialData must be T, not a different type | ||
| const _wrongInitialData: ReactFireOptions<string> = { initialData: 123 }; | ||
| void _wrongInitialData; | ||
|
|
||
| // @ts-expect-error startWithValue must be T, not a different type | ||
| const _wrongStartWithValue: ReactFireOptions<string> = { startWithValue: 123 }; | ||
| void _wrongStartWithValue; | ||
|
|
||
| // ---- snapshot hooks take the snapshot, data hooks take the data (#741) ---- | ||
| // | ||
| // Removing `T | any` also removed what was masking a mismatch: the raw snapshot | ||
| // hooks resolve to a DocumentSnapshot/QuerySnapshot, so that is what a correct | ||
| // initialData is. Without the hook-level fix, seeding them with a snapshot (the | ||
| // only value you can actually have) stops compiling. | ||
|
|
||
| import type { DocumentReference, DocumentSnapshot, Query, QuerySnapshot } from 'firebase/firestore'; | ||
| import type { useFirestoreCollection, useFirestoreDoc, useFirestoreDocData } from './firestore'; | ||
|
|
||
| declare const ref: DocumentReference<{ a: string }>; | ||
| declare const query: Query<{ a: string }>; | ||
| declare const snap: DocumentSnapshot<{ a: string }>; | ||
| declare const querySnap: QuerySnapshot<{ a: string }>; | ||
| declare const docHook: typeof useFirestoreDoc; | ||
| declare const collectionHook: typeof useFirestoreCollection; | ||
| declare const dataHook: typeof useFirestoreDocData; | ||
|
|
||
| void (() => docHook(ref, { initialData: snap })); | ||
| void (() => collectionHook(query, { initialData: querySnap })); | ||
| void (() => dataHook(ref, { initialData: { a: 'x' } })); | ||
|
|
||
| // @ts-expect-error a snapshot hook must not accept the unwrapped data type | ||
| void (() => docHook(ref, { initialData: { a: 'x' } })); | ||
|
|
||
| // @ts-expect-error a data hook must not accept a snapshot | ||
| void (() => dataHook(ref, { initialData: snap })); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think any of these are actually used, and agree deleting is the right thing, but this is technically a breaking change. Let's leave this for now, since it isn't hurting anything (unless it is, in which case let me know)
Please add an issue reminding us to remove all of these in v5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Both are kept as exports (no breaking removal), with a comment marking them unused-and-slated-for-v5. Filed #754 to remove them.
One heads-up: tightening
initialDatatoTshiftscheckinitialData's inferred return type fromanytounknown(visible in its regenerated doc). It's unused internally and on the v5 chopping block, so I left it rather than adding a cast to a dead export, but flagging in case you'd rather I pin it.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note it now also covers
startWithValue,ClaimsCheckandAuthCheck;startWithValueis not type-only,useObservablereads it as aninitialDatafallback.