Skip to content

Commit c3d95c3

Browse files
committed
fix: replace any with unknown/never in ParserMap types, format test.ts
Method shorthand on AMQPParser gives bivariance, so AMQPParser<unknown, unknown> accepts narrower parsers. Inference helpers use unknown/never in the slot we discard so eslint no-explicit-any is satisfied without disable comments.
1 parent f42b032 commit c3d95c3

2 files changed

Lines changed: 8 additions & 5 deletions

File tree

src/amqp-codec-registry.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { isPlainBody } from "./amqp-publisher.js"
44

55
// 1. Define a type that represents a map of different Parsers
66
export type ParserMap = {
7-
[K: string]: AMQPParser<any, any>
7+
[K: string]: AMQPParser<unknown, unknown>
88
}
99

1010
// 2. The ParserRegistry type uses a Mapped Type to preserve the unique In/Out of each key
@@ -41,8 +41,8 @@ export function createParserRegistry<T extends ParserMap>(
4141
return parsers
4242
}
4343

44-
export type InferParserInput<P> = P extends AMQPParser<infer TInput, any> ? TInput : never
45-
export type InferParserOutput<P> = P extends AMQPParser<any, infer Out> ? Out : never
44+
export type InferParserInput<P> = P extends AMQPParser<infer TInput, unknown> ? TInput : never
45+
export type InferParserOutput<P> = P extends AMQPParser<never, infer Out> ? Out : never
4646

4747
export type CoderMap = { [K: string]: AMQPCoder }
4848
export type CoderRegistry<T extends CoderMap> = { readonly [K in keyof T & string]: T[K] }
@@ -213,4 +213,3 @@ export async function decodeMessage(msg: AMQPMessage, parsers: ParserMap, coders
213213
;(msg as { body: unknown }).body = await decodeAndParse(parsers, coders, msg._rawBytes, msg.properties)
214214
}
215215
}
216-

test/test.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -810,7 +810,11 @@ test("can republish in consume block without race condition", async () => {
810810
await ch.basicPublish("", q.name, "x".repeat(500))
811811
const consumer = await ch.basicConsume(q.name, { noAck: false }, async (msg) => {
812812
if (msg.deliveryTag < 10000) {
813-
await Promise.all([ch.basicPublish("", q.name, msg._rawBytes), ch.basicPublish("", q.name, msg._rawBytes), msg.ack()])
813+
await Promise.all([
814+
ch.basicPublish("", q.name, msg._rawBytes),
815+
ch.basicPublish("", q.name, msg._rawBytes),
816+
msg.ack(),
817+
])
814818
} else if (msg.deliveryTag === 10000) {
815819
await msg.ack()
816820
await consumer.cancel()

0 commit comments

Comments
 (0)