Skip to content

Commit cc707fc

Browse files
committed
fix(types): fixed generics again
1 parent 2b94645 commit cc707fc

File tree

7 files changed

+32
-23
lines changed

7 files changed

+32
-23
lines changed

src/global.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ declare module 'pouchdb-utils' {
77
}
88

99
declare module 'pouchdb-selector-core' {
10-
export function matchesSelector<T extends {}>(
10+
export function matchesSelector<T extends Record<string, unknown>>(
1111
doc: PouchDB.Core.Document<T>,
1212
selector: PouchDB.Find.Selector
1313
): boolean

src/subscription.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { clone } from 'pouchdb-utils'
22

3-
export type DocsCallback<T extends {}> = (
3+
export type DocsCallback<T extends Record<string, unknown>> = (
44
deleted: boolean,
55
id: PouchDB.Core.DocumentId,
66
doc?: PouchDB.Core.Document<T>
@@ -22,7 +22,7 @@ interface SubscriptionToAView {
2222
feed: PouchDB.Core.Changes<Record<string, unknown>>
2323
callbacks: Set<ViewCallback>
2424
}
25-
export type subscribeToDocs = <T extends {}>(
25+
export type subscribeToDocs = <T extends Record<string, unknown>>(
2626
ids: PouchDB.Core.DocumentId[] | null,
2727
callback: DocsCallback<T>
2828
) => () => void
@@ -44,7 +44,7 @@ export default class SubscriptionManager {
4444
pouch.once('destroyed', this.#destroyListener)
4545
}
4646

47-
subscribeToDocs<T extends {}>(
47+
subscribeToDocs<T extends Record<string, unknown>>(
4848
ids: PouchDB.Core.DocumentId[] | null,
4949
callback: DocsCallback<T>
5050
): () => void {

src/useAllDocs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { useDeepMemo, CommonOptions } from './utils'
88
* Get all docs or a slice of all docs and subscribe to their updates.
99
* @param options PouchDB's allDocs options.
1010
*/
11-
export default function useAllDocs<Content extends {}>(
11+
export default function useAllDocs<Content extends Record<string, unknown>>(
1212
options?: CommonOptions &
1313
(
1414
| PouchDB.Core.AllDocsWithKeyOptions

src/useDoc.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { useContext } from './context'
44
import useStateMachine, { ResultType } from './state-machine'
55
import type { CommonOptions } from './utils'
66

7-
type DocResultType<T extends {}> = ResultType<{
7+
type DocResultType<T extends Record<string, unknown>> = ResultType<{
88
doc: (PouchDB.Core.Document<T> & PouchDB.Core.GetMeta) | null
99
}>
1010

@@ -14,7 +14,7 @@ type DocResultType<T extends {}> = ResultType<{
1414
* @param {object} [options] - PouchDB get options. Excluding 'open_revs'.
1515
* @param {object|function} [initialValue] - Value that should be returned while fetching the doc.
1616
*/
17-
export default function useDoc<Content extends {}>(
17+
export default function useDoc<Content extends Record<string, unknown>>(
1818
id: PouchDB.Core.DocumentId,
1919
options?: (PouchDB.Core.GetOptions & CommonOptions) | null,
2020
initialValue?: (() => Content) | Content
@@ -126,7 +126,7 @@ export default function useDoc<Content extends {}>(
126126
dispatch({
127127
type: 'loading_finished',
128128
payload: {
129-
doc: doc as PouchDB.Core.Document<Content> &
129+
doc: doc as unknown as PouchDB.Core.Document<Content> &
130130
PouchDB.Core.GetMeta,
131131
},
132132
})

src/useFind.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export interface FindHookOptions extends CommonOptions {
6161
* Query, and optionally create, a Mango index and subscribe to its updates.
6262
* @param {object} [opts] A combination of PouchDB's find options and create index options.
6363
*/
64-
export default function useFind<Content extends {}>(
64+
export default function useFind<Content extends Record<string, unknown>>(
6565
options: FindHookOptions
6666
): ResultType<PouchDB.Find.FindResponse<Content>> {
6767
const { pouchdb: pouch, subscriptionManager } = useContext(options.db)

src/usePouch.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { useContext } from './context'
44
* Get access to the PouchDB database that is provided by the provider.
55
* @param {string | undefined} dbName Select the database to be returned by its name/key.
66
*/
7-
export default function usePouch<T extends {}>(
7+
export default function usePouch<T extends Record<string, unknown>>(
88
dbName?: string
99
): PouchDB.Database<T> {
1010
return useContext(dbName).pouchdb as PouchDB.Database<T>

src/useView.ts

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,28 @@ import type SubscriptionManager from './subscription'
66
import useStateMachine, { ResultType, Dispatch } from './state-machine'
77
import { useDeepMemo, CommonOptions } from './utils'
88

9-
type ViewResponseBase<Result extends {}> = PouchDB.Query.Response<Result> & {
10-
/**
11-
* Include an update_seq value indicating which sequence id of the underlying database the view
12-
* reflects.
13-
*/
14-
update_seq?: number | string
15-
}
9+
type ViewResponseBase<Result extends Record<string, unknown>> =
10+
PouchDB.Query.Response<Result> & {
11+
/**
12+
* Include an update_seq value indicating which sequence id of the underlying database the view
13+
* reflects.
14+
*/
15+
update_seq?: number | string
16+
}
1617

17-
export type ViewResponse<T extends {}> = ResultType<ViewResponseBase<T>>
18+
export type ViewResponse<T extends Record<string, unknown>> = ResultType<
19+
ViewResponseBase<T>
20+
>
1821

1922
/**
2023
* Query a view and subscribe to its updates.
2124
* @param {string | function | object} fun The name of the view or a temporary view.
2225
* @param {object} [opts] PouchDB's query-options
2326
*/
2427
export default function useView<
25-
Content extends {},
26-
Result extends {},
27-
Model extends {} = Content
28+
Content extends Record<string, unknown>,
29+
Result extends Record<string, unknown>,
30+
Model extends Record<string, unknown> = Content
2831
>(
2932
fun: string | PouchDB.Map<Model, Result> | PouchDB.Filter<Model, Result>,
3033
opts?: PouchDB.Query.Options<Model, Result> & {
@@ -139,7 +142,10 @@ export default function useView<
139142
* @param fn Name of the view.
140143
* @param option PouchDB's query options.
141144
*/
142-
function doDDocQuery<Model extends {}, Result extends {}>(
145+
function doDDocQuery<
146+
Model extends Record<string, unknown>,
147+
Result extends Record<string, unknown>
148+
>(
143149
dispatch: Dispatch<PouchDB.Query.Response<Result>>,
144150
pouch: PouchDB.Database<Record<string, unknown>>,
145151
subscriptionManager: SubscriptionManager,
@@ -281,7 +287,10 @@ function doDDocQuery<Model extends {}, Result extends {}>(
281287
* @param fn The temporary view.
282288
* @param option PouchDB's query options.
283289
*/
284-
function doTemporaryQuery<Model extends {}, Result extends {}>(
290+
function doTemporaryQuery<
291+
Model extends Record<string, unknown>,
292+
Result extends Record<string, unknown>
293+
>(
285294
dispatch: Dispatch<PouchDB.Query.Response<Result>>,
286295
pouch: PouchDB.Database<Record<string, unknown>>,
287296
subscriptionManager: SubscriptionManager,

0 commit comments

Comments
 (0)