Typescript warns that a .svelte file import into a test file doesn't exist.
See original GitHub issueDescribe 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.
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:
- Created a year ago
- Comments:5 (4 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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 notsrc/test
, I definitely agree that it should work there - waiting on input from other maintainers.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.