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

Allow ignoring certain TS suggestion-level diagnostic codes #28825

Open
jsayol opened this issue Dec 3, 2018 · 17 comments
Open

Allow ignoring certain TS suggestion-level diagnostic codes #28825

jsayol opened this issue Dec 3, 2018 · 17 comments
Labels
In Discussion Not yet reached consensus Suggestion An idea for TypeScript

Comments

@jsayol
Copy link

jsayol commented Dec 3, 2018

Related to what was discussed in microsoft/vscode#61326.
Would provide more granularity to the settings introduced with microsoft/vscode#46590.

It might be useful to introduce a new setting to ignore certain suggestion diagnostic codes while still keeping suggestion diagnostics enabled, rather than having to disable them altogether.

What I'm proposing is to introduce 2 new settings, javascript.suggestionActions.ignoredCodes and typescript.suggestionActions.ignoredCodes. These would take a list of suggestion diagnostic codes that the user wants to ignore, given as a string of either comma- or space-separated code numbers.

Example:

{
  // ...

  "typescript.suggestionActions.enabled": true,
  "typescript.suggestionActions.ignoredCodes": "7043, 80006"

  // ...
}

This list would only be checked when a suggestion-level diagnostic is received, so including non-suggestion-level diagnostic codes in the list would have no effect (errors and messages would not be ignored).

@vscodebot
Copy link

vscodebot bot commented Dec 3, 2018

@mjbvz mjbvz transferred this issue from microsoft/vscode Dec 3, 2018
@mjbvz mjbvz removed their assignment Dec 3, 2018
@mjbvz
Copy link
Contributor

mjbvz commented Dec 3, 2018

@DanielRosenwasser We can implement the filtering on the VS Code side but should consider if we want a consistent story for TS.

@jsayol
Copy link
Author

jsayol commented Dec 3, 2018

@mjbvz That's actually a better idea, adding those settings as compiler options instead.

The diagnostics setting could be extended to not only support a boolean, but to also accept an object with include and exclude arrays of codes. These 2 should be mutually exclusive, I don't see any situation where it would make sense to have both.

So for example, instead of fully disabling diagnostics as it can be done now, the user could do the following to enable all diagnostics except for some of them:

{
  "compilerOptions": {
    "diagnostics": {
      "exclude": [7043, 80006]
    }
  }
}

Or, similarly, only enable some of the diagnostics:

{
  "compilerOptions": {
    "diagnostics": {
      "include": [80003]
    }
  }
}

If it's decided to go that way, it might be worth assigning string identifiers to the diagnostic codes. Something like this would be much more readable:

{
  "compilerOptions": {
    "diagnostics": {
      "exclude": [
        "better-variable-type-may-be-inferred",
        "may-be-converted-to-async-function"
      ]
    }
  }
}

@weswigham
Copy link
Member

@DanielRosenwasser

If it's decided to go that way, it might be worth assigning string identifiers to the diagnostic codes

I still agree with this sentiment~

@weswigham weswigham added Suggestion An idea for TypeScript In Discussion Not yet reached consensus labels Dec 4, 2018
@OneCyrus
Copy link

OneCyrus commented Dec 5, 2018

may be we can add there a file exclusion for gradual migration (to e.g. strict mode) too? exclude those rules for a certain globbing pattern only.

@javaxiu
Copy link

javaxiu commented Oct 18, 2019

want this feature too, mention that awesome-typescript-loader support this feature with the config item ignoreDiagnostics ,I wish that is was supportted by typescript it self

@michens
Copy link
Contributor

michens commented Jan 27, 2020

Please provide a way to set these per file (or at least per file type). Some of the suggestions are great in TS files where they will be transpiled away, but should not be suggested for JS files which still need to run directly in older environments.

@orassayag
Copy link

orassayag commented Dec 17, 2020

Is there any progress with this feature? I would like to remove some VSCode suggestions.
I would like an option to remove this:
Untitled

@karlhorky
Copy link
Contributor

Input from the extension ecosystem: this would help with implementing features where a TypeScript language service plugin wants to allow configuration of ignoring certain errors:

frigus02/typescript-sql-tagged-template-plugin#11 (comment)

@tomaszs
Copy link

tomaszs commented Feb 24, 2023

What is the status?

@wenfangdu
Copy link

Something like this would be great:
image
Ref: https://github.com/typescript-language-server/typescript-language-server#workspacedidchangeconfiguration

@Drag13
Copy link

Drag13 commented Oct 11, 2023

Still a valid point. Any progress here?

@me4502
Copy link
Member

me4502 commented Nov 22, 2023

Some of these diagnostics appear to impair functionality of VSCode (and presumably other IDEs using ts server) when not using specific libraries. For example, diagnostic 2593,

(Cannot find name 'describe'. Do you need to install type definitions for a test runner? Try npm i --save-dev @types/jest or npm i --save-dev @types/mocha and then add 'jest' or 'mocha' to the types field in your tsconfig.)

disables the normal VSCode import suggestions and removes both describe and it from the "Add all missing imports" action.

This diagnostic code is making the assumption that global types are being injected by a test framework, which is not the case by default on Vitest, and is not actually available when running Jest under ESM or when using the inbuilt Node test runner. This means IDE import actions are partially broken for these cases due to this diagnostic.

@derammo
Copy link

derammo commented Dec 4, 2023

I'm don't know enough about the code base to take this through the process of adding a compiler option, which presumably touches protocols, command line, etc. There would also need to be tests to submit it, but the code to actually make this work is extremely short. Here is an implementation:

https://github.com/microsoft/TypeScript/compare/main...derammo:TypeScript:derammo_suppressDiagnostics?expand=1

@patrickReiis
Copy link

Any status? How can I get rid of 80005: 'require' call may be converted to an import.?

@rootgrandfather
Copy link

any progress? god?

@YehudaKremer
Copy link

For TypeScript diagnostic errors you can use Disable TS Errors extension.

Works well for me, for example (settings.json):

{
  "editor.formatOnSave": true,
  "disableTsErrors.customizations": [
    {
      "code": [
        2304,
        2322,
        2339
      ],
      "severity": "off"
    }
  ]
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
In Discussion Not yet reached consensus Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests