quick-lint / quick-lint-js

quick-lint-js finds bugs in JavaScript programs
https://quick-lint-js.com
GNU General Public License v3.0
1.52k stars 191 forks source link

E0214 with types from lib.dom in typescript project #1180

Closed stevebeauge closed 7 months ago

stevebeauge commented 7 months ago

Using the default configuration in a browser only project, I get an error on this code:

const commonHeaders: HeadersInit = {
    Accept: "application/json",
    "Content-Type": "application/json"
};

I have no import on the HeadersInit, because it's imported through the "lib": ["es5", "dom", "es2015.collection", "es2015.promise", "es6", "es7", "es2019", "es2020"] present in my tsconfig file (guessing dom is the important one)

Quick lint throws:

use of undeclared type: HeadersInit quick-lint-js E0214.

I can work around the error by creating a config file like this:

{
    "globals": {
        "HeadersInit": {
            "writable": false
        }
    }
}

This makes quick lint happy.

I'm expecting to have quick-lint-js works out of the box with the standard types imported from the dom lib.

Or did I misunderstand something?

strager commented 7 months ago

I'm expecting to have quick-lint-js works out of the box with the standard types imported from the dom lib.

You're right that quick-lint-js's "global-groups: ["browser"] (enabled by default) should declare a type called HeadersInit.

strager commented 7 months ago

Fixed in Git commit b8c59d3bec9159f93a350164c071b873273b883c. This will be released in version 3.1.0 soon.

strager commented 7 months ago

Version 3.1.0 has shipped with the fix. (It actually shipped 4 days ago, but I forgot to mention it here...)