Maik
Maik3w ago

Inconsistent type checking of overloaded generic functions on publish

Hi, thanks for taking the time to read this. I'm running into inconsistent type checking behaviour of overloaded generic functions between deno check and deno publish. I would expect both to exhibit the same kind of type checking behaviour but it seems I've found an edge-case. The culprit function is defined as follows:
export function chain<R>(handler: Handler<R>): Handler<R>;
export function chain<R, P>(middleware: Middleware<R, P>): Chain<R, P>;
export function chain<R, P>(middleware: Handler<R> | Middleware<R, P>): Handler<R> | Chain<R, P> { ... }
export function chain<R>(handler: Handler<R>): Handler<R>;
export function chain<R, P>(middleware: Middleware<R, P>): Chain<R, P>;
export function chain<R, P>(middleware: Handler<R> | Middleware<R, P>): Handler<R> | Chain<R, P> { ... }
Running deno check reports no type errors. However, using deno publish it reports the following error:
error: Failed ensuring public API type output is valid.

TS6205 [ERROR]: All type parameters are unused.
export function chain<R, P>(param0?: any): any {
~~~~~~
error: Failed ensuring public API type output is valid.

TS6205 [ERROR]: All type parameters are unused.
export function chain<R, P>(param0?: any): any {
~~~~~~
The package exports defined in mod.ts have chain exported as a simple re-export: export { chain } from '...';. Some things I have learnt already: - This is due to the noUnusedParameters compiler option, disabling said option removes the type error. - The error is only reported when I export it as part of mod.ts (i.e. only when it is 'exported publicly'). - Using a @ts-ignore rule mitigates the type error. Of course I could refactor to avoid the use of overloads but I figured this might be worth investigating. Once again, thanks for taking the time to read into this. If anything remains unclear, I'd be more than happy to provide more information.
2 Replies
marvinh.
marvinh.3w ago
Can you file an issue for that (copy & paste your message) here https://github.com/denoland/deno/issues ?
Maik
MaikOP3w ago
I’ve created the following issue: https://github.com/denoland/deno/issues/30285
GitHub
Inconsistent type checking of overloaded generic functions on publi...
Version: Deno v2.4.3 Hi, thanks for taking the time to read this. I&#39;m running into inconsistent type checking behaviour of overloaded generic functions between deno check and deno publish. I wo...

Did you find this page helpful?