c4spar / deno-cliffy

Command line framework for deno 🦕 Including Commandline-Interfaces, Prompts, CLI-Table, Arguments Parser and more...
https://cliffy.io
MIT License
929 stars 65 forks source link

prompt/_generic_list.ts fails to type-check on rc4 #744

Closed cscheid closed 5 days ago

cscheid commented 1 week ago

I can't get Cliffy's latest version to type check on deno 1.46.3:

$ cat main.ts
import { Checkbox } from "https://deno.land/x/cliffy@v1.0.0-rc.4/prompt/checkbox.ts";
$ deno check --all main.ts
Check file:///Users/cscheid/Desktop/daily-log/2024/09/24/cliffy/main.ts
error: TS2345 [ERROR]: Argument of type '(a: MatchedOption<TValue, TOption, TGroup>, b: MatchedOption<TValue, TOption, TGroup>) => number' is not assignable to parameter of type '(a: MatchedOption<unknown, GenericListOptionSettings<unknown>, GenericListOptionGroupSettings<unknown, GenericListOptionSettings<unknown>>>, b: MatchedOption<...>) => number'.
  Types of parameters 'a' and 'a' are incompatible.
    Type 'MatchedOption<unknown, GenericListOptionSettings<unknown>, GenericListOptionGroupSettings<unknown, GenericListOptionSettings<unknown>>>' is not assignable to type 'MatchedOption<TValue, TOption, TGroup>'.
      Type 'GenericListOptionSettings<unknown>' is not assignable to type 'TOption'.
        'TOption' could be instantiated with an arbitrary type which could be unrelated to 'GenericListOptionSettings<unknown>'.
        .sort(sortByDistance);
              ~~~~~~~~~~~~~~
    at https://deno.land/x/cliffy@v1.0.0-rc.4/prompt/_generic_list.ts:799:15

TS2322 [ERROR]: Type 'MatchedOption<unknown, GenericListOptionSettings<unknown>, GenericListOptionGroupSettings<unknown, GenericListOptionSettings<unknown>>>[]' is not assignable to type 'MatchedOption<TValue, TOption, TGroup>[]'.
  Type 'MatchedOption<unknown, GenericListOptionSettings<unknown>, GenericListOptionGroupSettings<unknown, GenericListOptionSettings<unknown>>>' is not assignable to type 'MatchedOption<TValue, TOption, TGroup>'.
          children,
          ~~~~~~~~
    at https://deno.land/x/cliffy@v1.0.0-rc.4/prompt/_generic_list.ts:805:11

    The expected type comes from property 'children' which is declared here on type 'MatchedOption<TValue, TOption, TGroup>'
      children: Array<MatchedOption<TValue, TOption, TGroup>>;
      ~~~~~~~~
        at https://deno.land/x/cliffy@v1.0.0-rc.4/prompt/_generic_list.ts:163:3

Found 2 errors.

More generally: what's the latest supported version of Cliffy and on what Deno version should I expect Cliffy to work?

We can't skip typechecking in our specific use case because we use the output of deno vendor. That makes all imports local, and then Cliffy causes Deno to refuse to run any code because of type-checking failures.

c4spar commented 1 week ago

I cannot reproduce this error. Type checking works just fine for me. cliffy is supporting the latest stable version of deno. The latest version of cliffy is 1.0.0-rc.5 and is published on jsr. The documentation for this version is not yet published.

cscheid commented 1 week ago

Hm. I see the same issue on 1.46.3 and rc.5:

$ deno
Deno 1.46.3
exit using ctrl+d, ctrl+c, or close()
REPL is running with all permissions allowed.
To specify permissions, run `deno repl` with allow flags.
>
$ cat main2.ts
import { Checkbox } from "jsr:@cliffy/prompt@1.0.0-rc.5";
$ deno vendor main2.ts
⚠️ Warning: `deno vendor` is deprecated and will be removed in Deno 2.0.
Add `"vendor": true` to your `deno.json` or use the `--vendor` flag instead.
Vendored 111 modules into vendor/ directory.

To use vendored modules, specify the `--import-map vendor/import_map.json` flag when invoking Deno subcommands or add an `"importMap": "<path_to_vendored_import_map>"` entry to a deno.json file.
$ deno check --all main2.ts --import-map=vendor/import_map.json
Check file:///Users/cscheid/Desktop/daily-log/2024/09/24/cliffy/main2.ts
error: TS2345 [ERROR]: Argument of type '(a: MatchedOption<TValue, TOption, TGroup>, b: MatchedOption<TValue, TOption, TGroup>) => number' is not assignable to parameter of type '(a: MatchedOption<unknown, GenericListOptionSettings<unknown>, GenericListOptionGroupSettings<unknown, GenericListOptionSettings<unknown>>>, b: MatchedOption<...>) => number'.
  Types of parameters 'a' and 'a' are incompatible.
    Type 'MatchedOption<unknown, GenericListOptionSettings<unknown>, GenericListOptionGroupSettings<unknown, GenericListOptionSettings<unknown>>>' is not assignable to type 'MatchedOption<TValue, TOption, TGroup>'.
      Type 'GenericListOptionSettings<unknown>' is not assignable to type 'TOption'.
        'TOption' could be instantiated with an arbitrary type which could be unrelated to 'GenericListOptionSettings<unknown>'.
        .sort(sortByDistance);
              ~~~~~~~~~~~~~~
    at file:///Users/cscheid/Desktop/daily-log/2024/09/24/cliffy/vendor/jsr.io/@cliffy/prompt/1.0.0-rc.5/_generic_list.ts:796:15

TS2322 [ERROR]: Type 'MatchedOption<unknown, GenericListOptionSettings<unknown>, GenericListOptionGroupSettings<unknown, GenericListOptionSettings<unknown>>>[]' is not assignable to type 'MatchedOption<TValue, TOption, TGroup>[]'.
  Type 'MatchedOption<unknown, GenericListOptionSettings<unknown>, GenericListOptionGroupSettings<unknown, GenericListOptionSettings<unknown>>>' is not assignable to type 'MatchedOption<TValue, TOption, TGroup>'.
          children,
          ~~~~~~~~
    at file:///Users/cscheid/Desktop/daily-log/2024/09/24/cliffy/vendor/jsr.io/@cliffy/prompt/1.0.0-rc.5/_generic_list.ts:802:11

    The expected type comes from property 'children' which is declared here on type 'MatchedOption<TValue, TOption, TGroup>'
      children: Array<MatchedOption<TValue, TOption, TGroup>>;
      ~~~~~~~~
        at file:///Users/cscheid/Desktop/daily-log/2024/09/24/cliffy/vendor/jsr.io/@cliffy/prompt/1.0.0-rc.5/_generic_list.ts:157:3

Found 2 errors.
c4spar commented 6 days ago

Ok strange, when i use deno vendor i can reproduce the issue with rc.5 but without deno vendor remote type-checking works fine for me with deno check --all. But i also noticed this issue is already fixed but not yet released. i will do a new release later.