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

Upgrade typescript to version 4 #4624

Draft
wants to merge 22 commits into
base: master
Choose a base branch
from
Draft

Upgrade typescript to version 4 #4624

wants to merge 22 commits into from

Conversation

bovine3dom
Copy link
Member

Build fails, presumably something that has changed for the metadata generator from ts 3 -> ts 4.

Logs:

$ sh scripts/build.sh
NodeObject {
  pos: -1,
  end: -1,
  flags: 8,
  modifierFlagsCache: 0,
  transformFlags: 1,
  parent: undefined,
  kind: 195,
  operator: 141,
  type: NodeObject {
    pos: -1,
    end: -1,
    flags: 8,
    modifierFlagsCache: 0,
    transformFlags: 1,
    parent: undefined,
    kind: 180,
    typeName: IdentifierObject {
      pos: -1,
      end: -1,
      flags: 8,
      modifierFlagsCache: 0,
      transformFlags: 0,
      parent: undefined,
      kind: 79,
      originalKeywordKind: undefined,
      escapedText: 'default_config',
      emitNode: [Object],
      symbol: [SymbolObject],
      typeArguments: undefined
    },
    typeArguments: undefined
  }
}
/home/deck/projects/tridactyl/compiler/gen_metadata.js:79
            throw new Error(`Unhandled kind (${typeNode.kind}) for ${typeNode}`);
            ^

Error: Unhandled kind (195) for [object Object]
    at toSimpleType (/home/deck/projects/tridactyl/compiler/gen_metadata.js:79:19)
    at toSimpleType (/home/deck/projects/tridactyl/compiler/gen_metadata.js:29:21)
    at /home/deck/projects/tridactyl/compiler/gen_metadata.js:50:75
    at Array.map (<anonymous>)
    at toSimpleType (/home/deck/projects/tridactyl/compiler/gen_metadata.js:50:66)
    at visit (/home/deck/projects/tridactyl/compiler/gen_metadata.js:109:23)
    at /home/deck/projects/tridactyl/compiler/gen_metadata.js:155:35
    at visitNodes (/home/deck/projects/tridactyl/node_modules/typescript/lib/typescript.js:31214:30)
    at forEachChildInSourceFile (/home/deck/projects/tridactyl/node_modules/typescript/lib/typescript.js:31573:20)
    at Object.forEachChild (/home/deck/projects/tridactyl/node_modules/typescript/lib/typescript.js:31988:47)

Node.js v18.11.0
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Includes #4623

Closes #4622

@bovine3dom
Copy link
Member Author

bovine3dom commented Mar 10, 2023

I absolutely must remember to fix the typedoc / :help theme before merging.

I think we might have got onto real errors now:

src/lib/messaging.ts:81:22 - error TS2344: Type 'Root[Type][Command]' does not satisfy the constraint '(...args: any) => any'.
  Type 'Root[Type][keyof Root[Type]]' is not assignable to type '(...args: any) => any'.
    Type 'Root[Type][string] | Root[Type][number] | Root[Type][symbol]' is not assignable to type '(...args: any) => any'.
      Type 'Root[Type][string]' is not assignable to type '(...args: any) => any'.
        Type 'Root[keyof Root][string]' is not assignable to type '(...args: any) => any'.
          Type 'Root[string][string] | Root[number][string] | Root[symbol][string]' is not assignable to type '(...args: any) => any'.
            Type 'Root[string][string]' is not assignable to type '(...args: any) => any'.

81     args: Parameters<Root[Type][Command]>
                        ~~~~~~~~~~~~~~~~~~~

src/lib/messaging.ts:91:15 - error TS2344: Type 'Root[Type][Command]' does not satisfy the constraint '(...args: any) => any'.
  Type 'Root[Type][keyof Root[Type]]' is not assignable to type '(...args: any) => any'.
    Type 'Root[Type][string] | Root[Type][number] | Root[Type][symbol]' is not assignable to type '(...args: any) => any'.
      Type 'Root[Type][string]' is not assignable to type '(...args: any) => any'.
        Type 'Root[keyof Root][string]' is not assignable to type '(...args: any) => any'.
          Type 'Root[string][string] | Root[number][string] | Root[symbol][string]' is not assignable to type '(...args: any) => any'.
            Type 'Root[string][string]' is not assignable to type '(...args: any) => any'.

91 ): ReturnType<Root[Type][Command]> {
                 ~~~~~~~~~~~~~~~~~~~

src/lib/messaging.ts:92:12 - error TS2349: This expression is not callable.
  Type '{}' has no call signatures.

92     return root[message.type][message.command](...message.args)
              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

src/lib/messaging.ts:98:33 - error TS2322: Type 'Root' is not assignable to type 'object'.

98             if (message.type in root) {
                                   ~~~~

  src/lib/messaging.ts:95:31
    95 export function setupListener<Root>(root: Root) {
                                     ~~~~
    This type parameter might need an `extends object` constraint.


Found 4 errors in the same file, starting at: src/lib/messaging.ts:81

I'll try to look at these remaining errors again tomorrow ... tonight I'm finding them pretty impenetrable.

@treapster
Copy link
Contributor

treapster commented Mar 12, 2023

Here is a pathetic attempt to fix typing
0001-Try-to-fix-more-typing-errors.txt

treapster and others added 2 commits March 14, 2023 12:53
The messages object in background.ts implicitly had a type
{ [key: string]: { [key: string]: (...args: any) => any } },
and was used as such in messaging.ts. Now that TypeScript is updated, it
got angry because the imported excmds_background and statsLogger are not
strictly { [key: string]: (...args: any) => any }. For excmd_functions
the problem were consts which are not functions. I namespaced all
functions and if we import only that namespace and use it in messaging,
typescript will be happy. I know namespaces are discouraged but i don't know
of other ways to separate functions from other parts of a file without
creating a new file for them. As for logger, i used a nasty cast because
what else can we do?
Using namespace also pisses off lint, and pretty seems to break
everything, so this patch is purely to make build work.
There are a fair few left to do - anything with _src_ in it is wrong
@bovine3dom
Copy link
Member Author

For some reason all the excmd doc-comments seem to have disappeared, but they work fine for the lib/config page.

I think all remaining linting errors are real errors
@treapster
Copy link
Contributor

It seems we can get away without namespace if we stop exporting anything but functions. I'm not sure if we need those exports, but it builds and works more-or-less.
0001-Remove-exported-consts-from-excmds.ts.txt

Needed to do this to make the new theme, apparently
One day we should probably work out how to make the
new runner, circus, fail fast
@bovine3dom
Copy link
Member Author

bovine3dom commented Mar 14, 2023

but it builds and works more-or-less.

So long as you don't try to use the command line on a non-Tridactyl page 👀. Tridactyl pages get access to the background script so presumably there's some problem with the messaging.

I applied the patch and pushed it to a different branch 7d6fcc8 because it was slightly annoying to rebase and I didn't want to have to do it again if we get it working :)

@treapster
Copy link
Contributor

So long as you don't try to use the command line on a non-Tridactyl page. Tridactyl pages get access to the background script so presumably there's some problem with the messaging.

Oops, you're right. But i guess we still need a solution without namespace(because it looks like someday they'll be deprecated), so i'll look into it.

@bovine3dom
Copy link
Member Author

There's something wrong with the e2e tests

        options.setBinary("/usr/bin/firefox-developer-edition")

in e2e.test.ts should make them run locally, I'll try to look tomorrow

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update to TypeScript 4
2 participants