Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typechecking breaks on class method with generic args #376

Closed
atjn opened this issue Apr 10, 2024 · 5 comments · Fixed by denoland/deno_graph#432 or denoland/deno_graph#435
Closed
Assignees
Labels
bug Something isn't working

Comments

@atjn
Copy link

atjn commented Apr 10, 2024

Hi :)

I believe I have found a very specifig bug in the JSR typechecker. If you define a class with a generic, then use the generic as the spread of arguments in a method and in an overload for the method, JSR will fail to understand the types and generate a type error.

Minimal reproduction

Create a Deno project with two files:

main.ts

export class argsToArray<ARGS extends unknown[]> {
  argsToArray(..._args: ARGS): void;
  argsToArray(..._args: ARGS): void {}
}

deno.json

{
  "name": "@test/test",
  "version": "0.0.1",
  "exports": {
    ".": "./main.ts"
  }
}

Then run:

deno publish --dry-run

You will see the following error:

error: Failed ensuring public API type output is valid.

TS2394 [ERROR]: This overload signature is not compatible with its implementation signature.
  argsToArray(..._args: ARGS): void;
  ~~~~~~~~~~~
    at file:///[...]/main.ts:2:3

TS2750 [ERROR]:     The implementation signature is declared here.
      argsToArray(param0?: any): any {
      ~~~~~~~~~~~
        at file:///[...]/main.ts:3:3

Notice that the implementation signature shown in the error is completely wrong. We do not have only a single parameter and it is not of type any.

This is on Deno 1.42.1 (latest) and JSR 0.12.1 (latest). This code runs perfectly fine on Deno and deno lint does not produce errors, so I am guessing that this is a bug in JSR.

This is currently blocking me from publishing my library to JSR.

@lucacasonato
Copy link
Member

Whoops, that is indeed a bug!

@lucacasonato lucacasonato added the bug Something isn't working label Apr 11, 2024
@lucacasonato
Copy link
Member

This seems to be caused by the interaction of spread + overload, not the generics. We'll fix this.

@atjn
Copy link
Author

atjn commented Apr 11, 2024

It is caused by all of these things. If you remove the generics, there is no type error. Also if you move the generic from the class definition to the function definition, there is no type error. Thanks for looking into it :)

@atjn
Copy link
Author

atjn commented Apr 12, 2024

@lucacasonato @dsherret this is not fixed in Deno 1.42.3 but it did get a new error message:

error: Failed ensuring public API type output is valid.

TS1047 [ERROR]: A rest parameter cannot be optional.
  argsToArray(...param0?: any): any {
                       ^
    at file:///[...]/main.ts:3:3

Notice again that the implementation details are wrong.

@lucacasonato
Copy link
Member

Will go out in a canary release later today hopefully.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Done
4 participants