Skip to content

Commit 581774a

Browse files
authored
fix: exactOptionalPropertyTypes TS option compatibility (#256)
1 parent e58ebf8 commit 581774a

26 files changed

Lines changed: 103 additions & 76 deletions

package-lock.json

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

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
"@semantic-release/git": "10.0.1",
5555
"@testing-library/react": "14.0.0",
5656
"@tsconfig/recommended": "1.0.3",
57+
"@tsconfig/strictest": "2.0.2",
5758
"@types/react": "18.2.33",
5859
"@typescript-eslint/eslint-plugin": "6.9.0",
5960
"@typescript-eslint/parser": "6.9.0",

src/database/useObjectValue.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ export type UseObjectValueResult<Value = unknown> = ValueHookResult<Value, Error
1010
export type UseObjectValueConverter<Value> = (snap: DataSnapshot) => Value;
1111

1212
export interface UseObjectValueOptions<Value> {
13-
converter?: UseObjectValueConverter<Value>;
14-
initialValue?: Value;
13+
converter?: UseObjectValueConverter<Value> | undefined;
14+
initialValue?: Value | undefined;
1515
}
1616

1717
/**
@@ -28,7 +28,7 @@ export interface UseObjectValueOptions<Value> {
2828
*/
2929
export function useObjectValue<Value = unknown>(
3030
query: Query | undefined | null,
31-
options?: UseObjectValueOptions<Value>,
31+
options?: UseObjectValueOptions<Value> | undefined,
3232
): UseObjectValueResult<Value> {
3333
const { converter = defaultConverter, initialValue = LoadingState } = options ?? {};
3434

src/database/useObjectValueOnce.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export type UseObjectValueOnceResult<Value = unknown> = ValueHookResult<Value, E
99
export type UseObjectValueOnceConverter<Value> = (snap: DataSnapshot) => Value;
1010

1111
export interface UseObjectValueOnceOptions<Value> {
12-
converter?: UseObjectValueOnceConverter<Value>;
12+
converter?: UseObjectValueOnceConverter<Value> | undefined;
1313
}
1414

1515
/**
@@ -25,7 +25,7 @@ export interface UseObjectValueOnceOptions<Value> {
2525
*/
2626
export function useObjectValueOnce<Value = unknown>(
2727
query: Query | undefined | null,
28-
options?: UseObjectValueOnceOptions<Value>,
28+
options?: UseObjectValueOnceOptions<Value> | undefined,
2929
): UseObjectValueOnceResult<Value> {
3030
const { converter = defaultConverter } = options ?? {};
3131

src/firestore/internal.spec.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,13 @@ describe("isAggregateSpecEqual", () => {
125125
expect(isAggregateSpecEqual(spec1, spec2)).toBe(false);
126126
});
127127

128+
it("different keys", () => {
129+
const spec1 = { count: count() };
130+
const spec2 = { total: count() };
131+
// @ts-expect-error Different specs
132+
expect(isAggregateSpecEqual(spec1, spec2)).toBe(false);
133+
});
134+
128135
it("different aggregations", () => {
129136
const spec1 = { value: count() };
130137
const spec2 = { value: average("abc") };

src/firestore/internal.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,5 +83,5 @@ export function isAggregateSpecEqual<T extends AggregateSpec>(a: T, b: T): boole
8383
return false;
8484
}
8585

86-
return Object.entries(a).every(([key, value]) => aggregateFieldEqual(value, b[key]));
86+
return Object.entries(a).every(([key, value]) => aggregateFieldEqual(value, b[key]!));
8787
}

src/firestore/useDocument.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export type UseDocumentResult<AppModelType = DocumentData> = ValueHookResult<Doc
1818
* Options to configure the subscription
1919
*/
2020
export interface UseDocumentOptions {
21-
snapshotListenOptions?: SnapshotListenOptions;
21+
snapshotListenOptions?: SnapshotListenOptions | undefined;
2222
}
2323

2424
/**
@@ -34,10 +34,10 @@ export interface UseDocumentOptions {
3434
*/
3535
export function useDocument<AppModelType = DocumentData, DbModelType extends DocumentData = DocumentData>(
3636
reference: DocumentReference<AppModelType, DbModelType> | undefined | null,
37-
options?: UseDocumentOptions,
37+
options?: UseDocumentOptions | undefined,
3838
): UseDocumentResult<AppModelType> {
3939
const { snapshotListenOptions } = options ?? {};
40-
const { includeMetadataChanges } = snapshotListenOptions ?? {};
40+
const { includeMetadataChanges = false } = snapshotListenOptions ?? {};
4141

4242
const onChange: UseListenOnChange<
4343
DocumentSnapshot<AppModelType, DbModelType>,

src/firestore/useDocumentData.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ export type UseDocumentDataResult<AppModelType = DocumentData> = ValueHookResult
1818
* Options to configure the subscription
1919
*/
2020
export interface UseDocumentDataOptions<AppModelType = DocumentData> {
21-
snapshotListenOptions?: SnapshotListenOptions;
22-
snapshotOptions?: SnapshotOptions;
23-
initialValue?: AppModelType;
21+
snapshotListenOptions?: SnapshotListenOptions | undefined;
22+
snapshotOptions?: SnapshotOptions | undefined;
23+
initialValue?: AppModelType | undefined;
2424
}
2525

2626
/**
@@ -37,11 +37,11 @@ export interface UseDocumentDataOptions<AppModelType = DocumentData> {
3737
*/
3838
export function useDocumentData<AppModelType = DocumentData, DbModelType extends DocumentData = DocumentData>(
3939
reference: DocumentReference<AppModelType, DbModelType> | undefined | null,
40-
options?: UseDocumentDataOptions<AppModelType>,
40+
options?: UseDocumentDataOptions<AppModelType> | undefined,
4141
): UseDocumentDataResult<AppModelType> {
4242
const { snapshotListenOptions, snapshotOptions } = options ?? {};
43-
const { includeMetadataChanges } = snapshotListenOptions ?? {};
44-
const { serverTimestamps } = snapshotOptions ?? {};
43+
const { includeMetadataChanges = false } = snapshotListenOptions ?? {};
44+
const { serverTimestamps = "none" } = snapshotOptions ?? {};
4545

4646
const onChange: UseListenOnChange<
4747
AppModelType,

src/firestore/useDocumentDataOnce.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ export type UseDocumentDataOnceResult<AppModelType = DocumentData> = ValueHookRe
1111
* Options to configure how the document is fetched
1212
*/
1313
export interface UseDocumentDataOnceOptions {
14-
source?: Source;
15-
snapshotOptions?: SnapshotOptions;
14+
source?: Source | undefined;
15+
snapshotOptions?: SnapshotOptions | undefined;
1616
}
1717

1818
/**
@@ -28,10 +28,10 @@ export interface UseDocumentDataOnceOptions {
2828
*/
2929
export function useDocumentDataOnce<AppModelType = DocumentData, DbModelType extends DocumentData = DocumentData>(
3030
reference: DocumentReference<AppModelType, DbModelType> | undefined | null,
31-
options?: UseDocumentDataOnceOptions,
31+
options?: UseDocumentDataOnceOptions | undefined,
3232
): UseDocumentDataOnceResult<AppModelType> {
3333
const { source = "default", snapshotOptions } = options ?? {};
34-
const { serverTimestamps } = snapshotOptions ?? {};
34+
const { serverTimestamps = "none" } = snapshotOptions ?? {};
3535

3636
const getData = useCallback(
3737
async (stableRef: DocumentReference<AppModelType, DbModelType>) => {

src/firestore/useDocumentOnce.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export type UseDocumentOnceResult<AppModelType = DocumentData> = ValueHookResult
1414
* Options to configure how the document is fetched
1515
*/
1616
export interface UseDocumentOnceOptions {
17-
source?: Source;
17+
source?: Source | undefined;
1818
}
1919

2020
/**
@@ -30,7 +30,7 @@ export interface UseDocumentOnceOptions {
3030
*/
3131
export function useDocumentOnce<AppModelType = DocumentData, DbModelType extends DocumentData = DocumentData>(
3232
reference: DocumentReference<AppModelType, DbModelType> | undefined | null,
33-
options?: UseDocumentOnceOptions,
33+
options?: UseDocumentOnceOptions | undefined,
3434
): UseDocumentOnceResult<AppModelType> {
3535
const { source = "default" } = options ?? {};
3636

0 commit comments

Comments
 (0)