Skip to content

Commit f82d02c

Browse files
authored
fix: restore empty object default (#228)
To make the type opt-in restore the empty object, otherwise extending classes become very verbose.
1 parent 05f253f commit f82d02c

File tree

3 files changed

+32
-15
lines changed

3 files changed

+32
-15
lines changed

packages/interface-blockstore/src/index.ts

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
/* eslint-disable @typescript-eslint/ban-types */
2+
// this ignore is so we can use {} as the default value for the options
3+
// extensions below - it normally means "any non-nullish value" but here
4+
// we are using it as an intersection type - see the aside at the bottom:
5+
// https://github.com/typescript-eslint/typescript-eslint/issues/2063#issuecomment-675156492
6+
17
import type {
28
AbortOptions,
39
AwaitIterable,
@@ -10,10 +16,10 @@ export interface Pair {
1016
block: Uint8Array
1117
}
1218

13-
export interface Blockstore <HasOptionsExtension = unknown,
14-
PutOptionsExtension = unknown, PutManyOptionsExtension = unknown,
15-
GetOptionsExtension = unknown, GetManyOptionsExtension = unknown, GetAllOptionsExtension = unknown,
16-
DeleteOptionsExtension = unknown, DeleteManyOptionsExtension = unknown> extends Store<CID, Uint8Array, Pair, HasOptionsExtension,
19+
export interface Blockstore <HasOptionsExtension = {},
20+
PutOptionsExtension = {}, PutManyOptionsExtension = {},
21+
GetOptionsExtension = {}, GetManyOptionsExtension = {}, GetAllOptionsExtension = {},
22+
DeleteOptionsExtension = {}, DeleteManyOptionsExtension = {}> extends Store<CID, Uint8Array, Pair, HasOptionsExtension,
1723
PutOptionsExtension, PutManyOptionsExtension,
1824
GetOptionsExtension, GetManyOptionsExtension,
1925
DeleteOptionsExtension, DeleteManyOptionsExtension> {

packages/interface-datastore/src/index.ts

+13-7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
/* eslint-disable @typescript-eslint/ban-types */
2+
// this ignore is so we can use {} as the default value for the options
3+
// extensions below - it normally means "any non-nullish value" but here
4+
// we are using it as an intersection type - see the aside at the bottom:
5+
// https://github.com/typescript-eslint/typescript-eslint/issues/2063#issuecomment-675156492
6+
17
import { Key } from './key.js'
28
import type {
39
Await,
@@ -11,18 +17,18 @@ export interface Pair {
1117
value: Uint8Array
1218
}
1319

14-
export interface Batch<BatchOptionsExtension = unknown> {
20+
export interface Batch<BatchOptionsExtension = {}> {
1521
put: (key: Key, value: Uint8Array) => void
1622
delete: (key: Key) => void
1723
commit: (options?: AbortOptions & BatchOptionsExtension) => Await<void>
1824
}
1925

20-
export interface Datastore <HasOptionsExtension = unknown,
21-
PutOptionsExtension = unknown, PutManyOptionsExtension = unknown,
22-
GetOptionsExtension = unknown, GetManyOptionsExtension = unknown,
23-
DeleteOptionsExtension = unknown, DeleteManyOptionsExtension = unknown,
24-
QueryOptionsExtension = unknown, QueryKeysOptionsExtension = unknown,
25-
BatchOptionsExtension = unknown
26+
export interface Datastore <HasOptionsExtension = {},
27+
PutOptionsExtension = {}, PutManyOptionsExtension = {},
28+
GetOptionsExtension = {}, GetManyOptionsExtension = {},
29+
DeleteOptionsExtension = {}, DeleteManyOptionsExtension = {},
30+
QueryOptionsExtension = {}, QueryKeysOptionsExtension = {},
31+
BatchOptionsExtension = {}
2632
> extends Store<Key, Uint8Array, Pair, HasOptionsExtension,
2733
PutOptionsExtension, PutManyOptionsExtension,
2834
GetOptionsExtension, GetManyOptionsExtension,

packages/interface-store/src/index.ts

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/* eslint-disable @typescript-eslint/ban-types */
2+
// this ignore is so we can use {} as the default value for the options
3+
// extensions below - it normally means "any non-nullish value" but here
4+
// we are using it as an intersection type - see the aside at the bottom:
5+
// https://github.com/typescript-eslint/typescript-eslint/issues/2063#issuecomment-675156492
16

27
/**
38
* An iterable or async iterable of values
@@ -16,10 +21,10 @@ export interface AbortOptions {
1621
signal?: AbortSignal
1722
}
1823

19-
export interface Store<Key, Value, Pair, HasOptionsExtension = unknown,
20-
PutOptionsExtension = unknown, PutManyOptionsExtension = unknown,
21-
GetOptionsExtension = unknown, GetManyOptionsExtension = unknown,
22-
DeleteOptionsExtension = unknown, DeleteManyOptionsExtension = unknown> {
24+
export interface Store<Key, Value, Pair, HasOptionsExtension = {},
25+
PutOptionsExtension = {}, PutManyOptionsExtension = {},
26+
GetOptionsExtension = {}, GetManyOptionsExtension = {},
27+
DeleteOptionsExtension = {}, DeleteManyOptionsExtension = {}> {
2328
/**
2429
* Check for the existence of a value for the passed key
2530
*

0 commit comments

Comments
 (0)