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

declares globals and exports in .d.ts file not recognized #1172

Open
KraXen72 opened this issue Jan 7, 2024 · 6 comments
Open

declares globals and exports in .d.ts file not recognized #1172

KraXen72 opened this issue Jan 7, 2024 · 6 comments
Labels
false positive Severe bug: quick-lint-js rejects valid code

Comments

@KraXen72
Copy link

KraXen72 commented Jan 7, 2024

sveltekit projects have a app.d.ts file. i use it like this:

declare global {
	interface NavLink {
		type: 'nav',
		title: string,
		href: string,
	}
	interface SubmenuSeparator {
		type: 'separator'
	}
}
// ...
export {};

However, the global types are not recognized and show:
image

tsconfig:

{
   "extends": "./.svelte-kit/tsconfig.json",
   "compilerOptions": {
   	"allowJs": true,
   	"checkJs": true,
   	"esModuleInterop": true,
   	"forceConsistentCasingInFileNames": true,
   	"resolveJsonModule": true,
   	"skipLibCheck": true,
   	"sourceMap": true,
   	"strict": true,
   	"target": "es2021"
   }
   // Path aliases are handled by https://kit.svelte.dev/docs/configuration#alias
   //
   // If you want to overwrite includes/excludes, make sure to copy over the relevant includes/excludes
   // from the referenced tsconfig.json - TypeScript does not merge them in
}

the "./.svelte-kit/tsconfig.json" is auto-generated / changes a lot, better to check a bare sveltekit starter project.

@vegerot
Copy link
Sponsor Contributor

vegerot commented Jan 7, 2024

I think the documentation needs to be improved.

  1. https://quick-lint-js.com/errors/E0214/ should mention how to add a global identifier to the config
  2. It should be easier to link to https://quick-lint-js.com/config/#_examples (I had to inspect element to get the id)

@strager strager added this to the 3.1 milestone Jan 7, 2024
@KraXen72
Copy link
Author

KraXen72 commented Jan 8, 2024

isn't globals just for declaring global variables one by one, or from enviroment sets? rather, i would need quick lint to recognize all the global types declared in app.d.ts and accept them as global

@strager
Copy link
Collaborator

strager commented Jan 10, 2024

quick-lint-js currently does not have a mechanism to take global variables declared in one file (app.d.ts in your case) and make them visible in another file.

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.)

@KraXen72 Which solutions sound good to you?

@strager strager removed this from the 3.1 milestone Jan 10, 2024
@KraXen72
Copy link
Author

while 1 is a good short term solution, i think 5 would be the best - scanning, relevant .d.ts files in the project (as far as i understand it, quicklint already does scanning and parsing in these files, since i get quicklint warnings in them), and parsing declare global blocks or other ways to declare global types, so quicklint recognizes global types and supresses the unknown type warning.

until this is implemented, a stopgap solution could be adding the option to disable the 'unknown type' warning, and leave known/unknown logic to the typescript LSP. I think many people use quicklint alongside the ts lsp, and not instead of it.

while importing and exporting types is likely a better way to manage types than globals, for a lot of projects i either don't have that many types (they fit in 1 file), or i don't want to put in the extra effort of import/export management for types too. yes, autoimport extensions exist and they do help, but i found they often make mistakes when modifying existing imports, or just refuse to create 'import type {}' imports.

@strager
Copy link
Collaborator

strager commented Jan 10, 2024

as far as i understand it, quicklint already does scanning and parsing in these files, since i get quicklint warnings in them

quick-lint-js only reports diagnostics for files you open in your editor. quick-lint-js does not scan all files in your project automatically.

I did want to implement project-wide analysis, but only by following import statements. Your use case suggests that I need to follow more than just import statements. I'll keep this in consideration when designing the analysis.

a stopgap solution could be adding the option to disable the 'unknown type' warning, and leave known/unknown logic to the typescript LSP.

#1174


In the next few months, I don't plan on implementing a proper fix for this issue. If you want to avoid the warnings but continue using quick-lint-js, you can configure quick-lint-js.

@strager strager added the false positive Severe bug: quick-lint-js rejects valid code label Jan 10, 2024
@KraXen72
Copy link
Author

for now, i'm using oxc linter, but i like quick-lint more - i'll try configuring it in a bit. thanks!

@strager strager changed the title sveltekit's app.d.ts which declares global and exports not recognized declares globals and exports in .d.ts file not recognized Apr 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
false positive Severe bug: quick-lint-js rejects valid code
Projects
None yet
Development

No branches or pull requests

3 participants