Skip to content

Commit 4012b85

Browse files
committed
fix: refine TypeScript error handling and update test cases across multiple packages
1 parent 1cc32ff commit 4012b85

13 files changed

Lines changed: 26 additions & 28 deletions

File tree

packages/iso-base/test/basex.test.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -576,22 +576,22 @@ describe('basex', () => {
576576
const description = fixture.description
577577
const alphabet = alphabets[fixture.alphabet] ?? fixture.alphabet
578578

579-
if (fixture.string !== undefined) {
580-
it(`decode should throw: ${description}`, () => {
581-
const codec = base(alphabet)
579+
if (fixture.string === undefined) {
580+
// Alphabet validation error
581+
it(`should throw on invalid alphabet: ${description}`, () => {
582582
assert.throws(
583-
() => codec.decode(/** @type {string} */ (fixture.string)),
583+
() => base(alphabet),
584584
(err) => {
585585
const regex = new RegExp(fixture.exception)
586586
return regex.test(/** @type {Error} */ (err).toString())
587587
}
588588
)
589589
})
590590
} else {
591-
// Alphabet validation error
592-
it(`should throw on invalid alphabet: ${description}`, () => {
591+
it(`decode should throw: ${description}`, () => {
592+
const codec = base(alphabet)
593593
assert.throws(
594-
() => base(alphabet),
594+
() => codec.decode(/** @type {string} */ (fixture.string)),
595595
(err) => {
596596
const regex = new RegExp(fixture.exception)
597597
return regex.test(/** @type {Error} */ (err).toString())

packages/iso-passkeys/src/cose.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,18 +70,18 @@ export function getCoseKeyType(key) {
7070
* @param {COSEALG} alg
7171
*/
7272
export function mapCoseAlgToWebCryptoAlg(alg) {
73-
// @ts-ignore
73+
// @ts-expect-error
7474
if ([COSEALG_MAP.RS1].includes(alg)) {
7575
return 'SHA-1'
7676
}
7777
if (
78-
// @ts-ignore
78+
// @ts-expect-error
7979
[COSEALG_MAP.ES256, COSEALG_MAP.PS256, COSEALG_MAP.RS256].includes(alg)
8080
) {
8181
return 'SHA-256'
8282
}
8383
if (
84-
// @ts-ignore
84+
// @ts-expect-error
8585
[COSEALG_MAP.ES384, COSEALG_MAP.PS384, COSEALG_MAP.RS384].includes(alg)
8686
) {
8787
return 'SHA-384'
@@ -92,7 +92,7 @@ export function mapCoseAlgToWebCryptoAlg(alg) {
9292
COSEALG_MAP.PS512,
9393
COSEALG_MAP.RS512,
9494
COSEALG_MAP.EdDSA,
95-
// @ts-ignore
95+
// @ts-expect-error
9696
].includes(alg)
9797
) {
9898
return 'SHA-512'

packages/iso-passkeys/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
"extends": "../../tsconfig.json",
33
"compilerOptions": {
44
"emitDeclarationOnly": true,
5-
"outDir": "dist"
5+
"outDir": "dist",
6+
"erasableSyntaxOnly": false
67
},
78
"references": [
89
{

packages/iso-ucan/src/utils.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export function nowInSeconds() {
4242
export async function cid(envelope) {
4343
const bytes = Envelope.encode({
4444
signature: envelope.signature,
45-
// @ts-ignore
45+
// @ts-expect-error
4646
signaturePayload: signaturePayload(envelope),
4747
})
4848
const hash = await sha256.digest(bytes)
@@ -333,7 +333,7 @@ export const selector = z.union([
333333
export const statement =
334334
/** @type {typeof z.lazy<z.ZodType<import('../src/types.js').Statement<unknown>>>} */ (
335335
z.lazy
336-
// @ts-ignore
336+
// @ts-expect-error
337337
)(() => {
338338
return z.union([
339339
z.tuple([

packages/iso-ucan/test/policy.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { assert, suite } from 'playwright-test/taps'
22
import { validate } from '../src/policy.js'
33
import type { Policy } from '../src/types.js'
4-
// @ts-ignore
54
import fixtures from './fixtures/policy.json' with { type: 'json' }
65

76
const policy = suite('policy')

packages/iso-ucan/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"path": "../iso-kv"
1919
}
2020
],
21-
"include": ["src", "scripts", "package.json", "test"],
21+
"include": ["src", "scripts", "package.json", "test", "test/**/*.json"],
2222
"exclude": ["node_modules", "dist", "out"],
2323
"typedocOptions": {
2424
"entryPointStrategy": "resolve",

packages/iso-web/src/env.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ function isElectron() {
1010
if (
1111
typeof window !== 'undefined' &&
1212
typeof window.process === 'object' &&
13-
// @ts-ignore
13+
// @ts-expect-error
1414
window.process.type === 'renderer'
1515
) {
1616
return true
@@ -56,12 +56,12 @@ export const IS_NODE =
5656
process.release.name === 'node' &&
5757
!IS_ELECTRON
5858
export const IS_WEBWORKER =
59-
// @ts-ignore - we either ignore worker scope or dom scope
59+
// @ts-expect-error - we either ignore worker scope or dom scope
6060
typeof importScripts === 'function' &&
6161
typeof globalThis !== 'undefined' &&
62-
// @ts-ignore - we either ignore worker scope or dom scope
62+
// @ts-expect-error - we either ignore worker scope or dom scope
6363
typeof WorkerGlobalScope !== 'undefined' &&
64-
// @ts-ignore - we either ignore worker scope or dom scope
64+
// @ts-expect-error - we either ignore worker scope or dom scope
6565
// eslint-disable-next-line no-undef
6666
globalThis instanceof WorkerGlobalScope
6767
export const IS_TEST =

packages/iso-web/src/http.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ export async function request(resource, options = {}) {
207207
}
208208

209209
const timeoutSignal =
210-
timeout !== false ? AbortSignal.timeout(timeout) : undefined
210+
timeout === false ? undefined : AbortSignal.timeout(timeout)
211211
const combinedSignals = anySignal([signal, timeoutSignal])
212212

213213
const _headers = new Headers(headers)

packages/iso-web/test/request.test.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ test('should retry with on response hook', async () => {
105105
test('should post json', async () => {
106106
server.use(
107107
http.post('https://local.dev/post', async ({ request }) => {
108-
// @ts-ignore
109108
return Response.json(await request.json(), { status: 200 })
110109
})
111110
)
@@ -159,7 +158,6 @@ test('should request 500 with json body', async () => {
159158
server.use(
160159
http.get('https://local.dev/error-json', ({ request }) => {
161160
const params = Object.fromEntries(new URL(request.url).searchParams)
162-
// @ts-ignore
163161
return HttpResponse.json(
164162
{ error: 'error' },
165163
{ status: Number(params.status) }

packages/iso-web/test/signals.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ test('should abort from any signal', () => {
2020
test('should ignore non signal', () => {
2121
const controllers = Array.from({ length: 5 }).map(() => new AbortController())
2222
const signals = controllers.map((c) => c.signal)
23-
// @ts-ignore
23+
// @ts-expect-error
2424
const signal = anySignal([...signals, { reason: 'test' }])
2525

2626
assert.equal(signal.aborted, false)

0 commit comments

Comments
 (0)