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

tsconfig.json option to ignore error TS2307 (or any specific error) #59429

Closed
6 tasks done
pferreir opened this issue Jul 26, 2024 · 5 comments
Closed
6 tasks done

tsconfig.json option to ignore error TS2307 (or any specific error) #59429

pferreir opened this issue Jul 26, 2024 · 5 comments

Comments

@pferreir
Copy link

πŸ” Search Terms

  • TS2307
  • Ignoring specific error

βœ… Viability Checklist

⭐ Suggestion

In our project we're using some convenience babel magic to add "virtual" packages which inject data into the client application. E.g.

import staticURL from 'indico-url:plugin_vc_zoom.static';

(fetches a URL from the backend's blueprint map)

This is obviously not appreciated by TypeScript, although it's not an issue in the end because we transpile it using Babel. On the other hand, VS Code does complain about it because TS does. Having the VS Code integration is useful and we'd like to continue using it and mute this particular error.

Right now the only option we have is to do something like:

// @ts-expect-error URL import
import staticURL from 'indico-url:plugin_vc_zoom.static';

... which is not great, especially if you end up in a file which has several of those.

Hence, it would be very useful if we could have an option to mute a particular error, or at least something which lets us tell Typescript that we don't want to see errors about unresolved modules (we get those from ESLint anyway).

I found this old discussion, from which there was no conclusion. Maybe there's something new?

πŸ“ƒ Motivating Example

"You're now able to silence particular errors, which is especially useful if you are already using a dedicated linting tool such as ESLint and want to have full control over which errors you see."

πŸ’» Use Cases

  1. What do you want to use this for?
  • Development in a large project where we are using also Babel + ESLint
  1. What shortcomings exist with current approaches?
  • Typescript is used both as a transpilation and static checking tool (by VSCode). It obviously complains about missing modules, which is good, and that would be fine if we were not depending on it also for VS Code "linting". I have no way to silence particular false positives unless I do so line by line.
  1. What workarounds are you using in the meantime?
  • Silencing errors line by line with // @ts-expect-error, which is far from ideal.
@MartinJohns
Copy link
Contributor

MartinJohns commented Jul 26, 2024

Why not just tell TypeScript that these are valid module imports, instead of hiding the error? Create a .d.ts file and add this line: declare module "indico-url:*";

It's better to work with the tools instead of against them. The problem especially with ignoring "any specific error" is that these errors still happen, and can still cause the parsing of the code to trip.

@BalaM314
Copy link

BalaM314 commented Jul 26, 2024

Add

declare module "indico-url:*.static" {
	export const staticURL: string;
	export default staticURL;
}

to a declaration file, this will tell typescript that any module of the form indico-url:*.static exists and has a default export of type "string".

@jcalz
Copy link
Contributor

jcalz commented Jul 26, 2024

Duplicate related to #19139

@MartinJohns
Copy link
Contributor

@jcalz That issue is about being able to distinguish between errors when using @ts-ignore, but this issue seems to be about being able to globally hide errors (using the tsconfig).

@pferreir
Copy link
Author

Thanks everyone, that seems to work. I had no idea you could use wildcards in module names. I'll close the issue.

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

No branches or pull requests

4 participants