question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unused '@ts-expect-error' directive in 6.2.0

See original GitHub issue

Summary

I use lighthouse in a typescript project with the following ts configs

"allowJs": true,
"maxNodeModuleJsDepth": 1,

The JSDoc types in lighthouse has been working nicely before 6.2.0.

On version 6.2.0, I start to see Unused '@ts-expect-error' directive errors

node_modules/lighthouse/lighthouse-core/gather/driver.js:296:5 - error TS2578: Unused '@ts-expect-error' directive.

296     // @ts-expect-error TODO(bckenny): tsc can't type event.params correctly yet,
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

node_modules/lighthouse/lighthouse-core/gather/gatherers/gatherer.js:25:5 - error TS2578: Unused '@ts-expect-error' directive.

25     // @ts-expect-error - assume that class name has been added to LH.GathererArtifacts.
       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

node_modules/lighthouse/lighthouse-core/lib/dependency-graph/base-node.js:132:5 - error TS2578: Unused '@ts-expect-error' directive.

132     // @ts-expect-error - in checkJs, ts doesn't know that CPUNode and NetworkNode *are* BaseNodes.
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

node_modules/lighthouse/lighthouse-core/lib/dependency-graph/base-node.js:267:5 - error TS2578: Unused '@ts-expect-error' directive.

267     // @ts-expect-error - only traverses graphs of Node, so force tsc to treat `this` as one
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

node_modules/lighthouse/lighthouse-core/lib/dependency-graph/base-node.js:273:7 - error TS2578: Unused '@ts-expect-error' directive.

273       // @ts-expect-error - queue has length so it's guaranteed to have an item
          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

node_modules/lighthouse/lighthouse-core/lib/dependency-graph/base-node.js:309:7 - error TS2578: Unused '@ts-expect-error' directive.

309       // @ts-expect-error - toVisit has length so it's guaranteed to have an item
          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
...

It seems the errors are happening because I don’t have "checkJs": true ts config set, as a result typescript raises errors for all the @ts-expect-error in js files. However setting"checkJs": true would cause typescript to raise errors all over the place for other js libraries.

I’m wondering if it’s possible to change @ts-expect-error back to @ts-ignore? Or are there other ways to work around it?

Thanks

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
brendankennycommented, Aug 11, 2020

Hi @oddui

I’m not sure if there’s a great way for us to fix this:

  • We want to use the benefits of @ts-expect-error (like self-alerting when they can be removed), so I don’t think we’ll want to move back to @ts-ignore.
  • We’ve also long talked about emitting type declaration files for consumers of lighthouse (#1773), but the plan there was probably not going to include internal files like network-recorder because we don’t necessarily want to commit to their current interface as a public API/requiring major version bumps for changes.

Possible other options:

  • write your own .d.ts declarations for those files (possibly automatically generated with --emitDeclarationOnly?). Annoying to do yourself and possibly fragile, but it should work
  • file a bug on typescript to not error on unused @ts-expect-error in js files when checkJs isn’t enabled. This does seem bug-like from at least your description of the situation (although I could be missing some of the pieces), but I also think there’s a good chance the issue would be closed with the recommendation to always use d.ts files for dependencies (either from the dependency itself or from DefinitelyTyped). Maybe worth trying, though?

Anyone reading this have other ideas?

1reaction
brendankennycommented, Sep 15, 2020
Read more comments on GitHub >

github_iconTop Results From Across the Web

error TS2578: Unused '@ts-expect-error' directive
Simple answer. You used // @ts-expect-error where is no error. I recommend replace it in VS Code via regex \s*\/\/\s*@ts-expect-error (to ...
Read more >
Build error: error TS2578: Unused '@ts-expect-error' directive
Hi, team, I receive error building redash. Have tried many options but failed to successfully build. ... src/visualizations/table/Renderer.tsx:125 ...
Read more >
ts-expect-error will report if there is no error. Unused '@ts ...
Discussion on: Getting Started With TypeScript​​ ts-expect-error will report if there is no error. True Sorry my mistake. Object keys is always a ......
Read more >
Bug listing with status RESOLVED with resolution OBSOLETE ...
Bug:1523 - "[IDEA] Offload work by distributing trivial ebuild maintenance to users, introduce a simple stability voting system and have a core team...
Read more >
March 2020 (version 1.44) - Visual Studio Code
Suggestions for the // @ts-expect-error directive. ... In addition, new versions of the LSP client (6.2.0-next.2) and server (6.2.0-next.2) libraries have ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found