Skip to content

Commit 6023831

Browse files
committed
fix: type errors
1 parent ec5e3d9 commit 6023831

File tree

13 files changed

+25
-20
lines changed

13 files changed

+25
-20
lines changed

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@
101101
},
102102
"./interface": {
103103
"import": "./src/interface.js"
104+
},
105+
"./bytes": {
106+
"import": "./src/bytes.js"
104107
}
105108
},
106109
"devDependencies": {

src/block.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ const tree = function * (source, base) {
7474
* @template T
7575
* @param {T} source
7676
* @param {string[]} path
77-
* @return {API.BlockCursorView}
77+
* @return {API.BlockCursorView<unknown>}
7878
*/
7979
const get = (source, path) => {
8080
/** @type {Record<string, any>} */
@@ -133,6 +133,7 @@ class Block {
133133

134134
/**
135135
* @param {string} [path]
136+
* @return {API.BlockCursorView<unknown>}
136137
*/
137138
get (path = '/') {
138139
return get(this.value, path.split('/').filter(Boolean))
@@ -206,7 +207,8 @@ const createUnsafe = ({ bytes, cid, value: maybeValue, codec }) => {
206207
if (value === undefined) throw new Error('Missing required argument, must either provide "value" or "codec"')
207208

208209
return new Block({
209-
cid: /** @type {API.CIDView<Code, Alg, V>} */(cid),
210+
// eslint-disable-next-line object-shorthand
211+
cid: /** @type {API.CIDView<Code, Alg, V>} */ (cid),
210212
bytes,
211213
value
212214
})

src/block/interface.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable @typescript-eslint/no-unnecessary-type-constraint */
12
/* eslint-disable no-use-before-define */
23
import { Link, CIDView, CIDVersion } from '../cid/interface.js'
34

@@ -51,8 +52,8 @@ export interface Block<
5152
cid: Link<T, C, A, V>
5253
}
5354

54-
export type BlockCursorView =
55-
| { value: unknown, remaining?: undefined }
55+
export type BlockCursorView<T extends unknown = unknown> =
56+
| { value: T, remaining?: undefined }
5657
| { value: CIDView, remaining: string }
5758

5859
export interface BlockView<
@@ -66,5 +67,5 @@ export interface BlockView<
6667

6768
links(): Iterable<[string, CIDView]>
6869
tree(): Iterable<string>
69-
get(path:string): BlockCursorView
70+
get(path:string): BlockCursorView<unknown>
7071
}

src/traversal.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import { base58btc } from './bases/base58.js'
22

33
/**
4-
* @template [T=unknown] - Logical type of the data encoded in the block
54
* @template [C=number] - multicodec code corresponding to codec used to encode the block
65
* @template [A=number] - multicodec code corresponding to the hashing algorithm used in CID creation.
76
* @template [V=0|1] - CID version
8-
* @typedef {import('./cid/interface').Link<T, C, A, V>} Link
7+
* @typedef {import('./cid/interface').CID<C, A, V>} CID
98
*/
109

1110
/**
@@ -17,10 +16,9 @@ import { base58btc } from './bases/base58.js'
1716
*/
1817

1918
/**
20-
* @template T
2119
* @param {Object} options
22-
* @param {Link} options.cid
23-
* @param {<T, C, A, V>(cid: Link<T, C, A, V>) => Promise<BlockView<T, C, A, V>|null>} options.load
20+
* @param {CID} options.cid
21+
* @param {(cid: CID) => Promise<BlockView|null>} options.load
2422
* @param {Set<string>} [options.seen]
2523
*/
2624
const walk = async ({ cid, load, seen }) => {

test/test-block.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ describe('block', () => {
6262
assert.deepStrictEqual(ret.remaining, 'test')
6363
assert.deepStrictEqual(String(ret.value), link.toString())
6464
ret = block.get('nope')
65+
6566
assert.deepStrictEqual(ret, { value: 'skip' })
6667
})
6768

test/test-bytes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* globals describe, it */
2-
import * as bytes from '../src/bytes.js'
2+
import * as bytes from 'multiformats/bytes'
33
import { assert } from 'chai'
44

55
describe('bytes', () => {

test/test-cid.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* globals describe, it */
22

33
import OLDCID from 'cids'
4-
import { fromHex, toHex, equals } from '../src/bytes.js'
4+
import { fromHex, toHex, equals } from 'multiformats/bytes'
55
import { varint, CID } from 'multiformats'
66
import * as CIDLib from 'multiformats/cid'
77
import { base58btc } from 'multiformats/bases/base58'

test/test-multibase-spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
'use strict'
33

44
import { bases } from 'multiformats/basics'
5-
import { fromString } from '../src/bytes.js'
5+
import { fromString } from 'multiformats/bytes'
66
import chai from 'chai'
77
import chaiAsPromised from 'chai-as-promised'
88

test/test-multibase.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* globals describe, it */
2-
import * as bytes from '../src/bytes.js'
2+
import * as bytes from 'multiformats/bytes'
33
import * as b2 from 'multiformats/bases/base2'
44
import * as b8 from 'multiformats/bases/base8'
55
import * as b10 from 'multiformats/bases/base10'

test/test-multicodec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* globals describe, it */
2-
import * as bytes from '../src/bytes.js'
2+
import * as bytes from 'multiformats/bytes'
33
import * as raw from 'multiformats/codecs/raw'
44
import * as json from 'multiformats/codecs/json'
55
import chai from 'chai'

0 commit comments

Comments
 (0)