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

Error use of undeclared type on types defined in `.d.ts` files #1214

Closed lifeisfakenews closed 3 months ago

lifeisfakenews commented 4 months ago

I am getting the error use of undeclared type on Tournament for the following code:

const tournament = query.data() as Tournament;
tournament.id = query.id;

even though, in vsc i can ctrl click on Tournament and it takes me to the definition in my types.d.ts file.

i can even hover it and it will show me the type information image

strager commented 3 months ago

Yeah, this looks to be the same issue as #1172. Currently quick-lint-js does not respect declare global in .d.ts files like this. I wrote some possible solutions in this comment: https://github.com/quick-lint/quick-lint-js/issues/1172#issuecomment-1884011471

Some possible solutions:

  1. Rewrite your code to use import instead of globals.
  2. Manually replicate app.d.ts to your quick-lint-js.config.
  3. Use a tool which replicates app.d.ts's globals to your quick-lint-js.config. (This tool does not yet exist.)
  4. Use a "globals-files" feature in quick-lint-js.config to specify source files. You would list "globals-files": ["src/app.d.ts"]. (This feature does not yet exist.)
  5. Have quick-lint-js auto-scan for .ts and .d.ts files which declare globals, similar to what TypeScript's compiler does. (This feature does not yet exist.)

I'm closing this as a duplicate.