question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Typescript warns that a .svelte file import into a test file doesn't exist.

See original GitHub issue

Describe the bug

I’m getting typescript warnings that a .svelte file that I’m importing in a test file doesn’t exist. But vitest runs fine. It seems to work if I add an includes in the project tsconfig.json to

"include": [
    "./.svelte-kit/ambient.d.ts",
    "src/**/*.js",
    "src/**/*.ts",
    "src/**/*.svelte",
    "src/**/*.js",
    "src/**/*.ts",
    "src/**/*.svelte",
    "test/**/*.ts",
    "test/**/*.js",
    "test/**/*.svelte"
  ],

and relaunch VS Code. But I’m wondering why test directory wasn’t included in .svelte-kit/tsconfig.json in the first place.

Screenshot 2022-08-05 at 14 59 39

Reproduction

https://github.com/manuganji/sjsf/tree/17b0742b3d25347a6c4be2186a7bd8f568ea32ae

Logs

No response

System Info

System:
    OS: macOS 12.1
    CPU: (8) x64 Apple M1
    Memory: 30.89 MB / 8.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 16.14.2 - ~/.nvm/versions/node/v16.14.2/bin/node
    Yarn: 1.22.17 - /opt/homebrew/bin/yarn
    npm: 8.10.0 - ~/.nvm/versions/node/v16.14.2/bin/npm
  Browsers:
    Chrome: 104.0.5112.79
    Firefox: 100.0.2
    Safari: 15.2
  npmPackages:
    @sveltejs/adapter-auto: next => 1.0.0-next.63 
    @sveltejs/kit: next => 1.0.0-next.403 
    svelte: ^3.44.0 => 3.49.0 
    vite: ^3.0.0 => 3.0.3

Severity

annoyance

Additional Information

No response

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
dummdidummcommented, Aug 5, 2022

Huh, didn’t know about that. That definitely changes things to some extend. I don’t know how that got in there, but if we have that convention and it goes into test and not src/test, I definitely agree that it should work there - waiting on input from other maintainers.

1reaction
dummdidummcommented, Aug 5, 2022

It’s not added because all the code is inside src - or rather, we thought that is what everyone does. You added another top level folder, so you need to adjust the tsconfig yourself. It sucks that there’s no mechanism to tell tsconfig to “add these includes in addition to the ones from extends”, so right now your solution is the only one that’s working. We can’t do “use all files in the current directory” because that also includes those from node_modules, the .svelte-kit folder and others which you might not want to have included.

Leaving this open for another maintainer to give their opinion on this (specifically, if we should adjust the includes/excludes of the generated tsconfig with a blacklist instead of a whitelist), but I say that there’s unfortunately nothing we can do about this.

The reason why you get this warning is that test is not in the includes config, so it creates a separate typechecking project which has no knowledge of the ambient type definitions which link to a definition which marks all *.svelte files as something that exists.

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeScript support in Svelte - Learn web development
In this article we took our to-do list application and ported it to TypeScript.
Read more >
Svelte: imported TypeScript files not recognized - Stack Overflow
so when it throws an error it means that Typescript is not working, So no changing the syntax is not the solution unfortunately....
Read more >
Loading data • Docs • SvelteKit
A +page.svelte file can have a sibling +page.js (or +page.ts ) that exports a load function, the return value of which is available...
Read more >
Typing Components in Svelte - Viget
In Svelte, components exist as standalone files that declare an interface of props, slots, and events. When using TypeScript, it's easy to ......
Read more >
Web Development Simplified with Svelte
js is generated from the JavaScript and HTML in each component and any other JavaScript in the app. 2. The file src/main.js contains...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found