Language-tools: Types from "typings" folder, aren't getting loaded in *.svelte scripts(lang=typescript) but works fine in other *.ts files

Created on 18 Jun 2020  路  12Comments  路  Source: sveltejs/language-tools

Shot 0003

Shot 0004

i checked many templates, tried many options, still couldn't get this correct,
same tsconfig is loaded by svelte and typscript server and still get two different results.
please let me know if anyone got this working correctly...

bug

Most helpful comment

@jasonlyu123 this is a sample repo i made, with what's working and what's not...
https://github.com/Dulanjala007/sapper-typescript-graphql-template

All 12 comments

Could you post your tsconfig json and the log from VSCode Output->Svelte on fresh startup?

tsconfig.json
{
"compilerOptions": {
"lib": [
"DOM",
"WebWorker"
],
"target": "ES2016",
"allowSyntheticDefaultImports": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"moduleResolution": "node",
"skipLibCheck": true,
"strict": true,
"typeRoots": ["node_modules/@types", "typings", "node_modules/svelte/types"],
"types": ["@sapper", "svelte", "cypress-svelte-unit-test"]
},
"include": [
"src/*/"
],
"exclude": [
"node_modules"
]
}

svelte.config.js

const sveltePreprocess = require('svelte-preprocess');
const dev = process.env.NODE_ENV === 'development';

module.exports = {
preprocess: sveltePreprocess({
typescript: {
transpileOnly: dev,
},
}),
};

Svelte Output :-

Initialize language server at /workspace
Trying to load config for /workspace/frontend/src/routes/_layout.svelte
Initialize new ts service at /workspace/frontend/tsconfig.json
Found config at /workspace/frontend/svelte.config.js
Using Svelte v3.23.2 from /workspace/frontend/node_modules/svelte/compiler
error TS2688: Cannot find type definition file for 'svelte'.

Using Svelte v3.23.2 from /workspace/frontend/node_modules/svelte/compiler

Can you provide a sample repo? I can't even make it work in ts.

@jasonlyu123 this is a sample repo i made, with what's working and what's not...
https://github.com/Dulanjala007/sapper-typescript-graphql-template

The types options is overrided by our default option.

https://github.com/sveltejs/language-tools/blob/16cece264f4a2a108fc90c3f4ce747d78e109805/packages/language-server/src/plugins/typescript/service.ts#L176
Unlike Object.merge or destructuring the existingOption parameter here is taking priority. The part of overriding with the default one is pretty old, it exists in the old repo. The types override are my fault, I thought it is the other way around. @dummdidumm what do you think the original intention is?

Honestly I don't know why existingOption is set, it was in the old repo and I never touched it. My guess is that it's important for files to get the correct initial files (svelte files, svelte node_module definitions), and that some of the options are set to not downlevel-transpile (targetLatest). Removing types from it and applying it later (check if it's set, if not, add it to the array) should fix the problem, right?

Yeah

is there a workaround for the time being? something i can edit or update to fix it temperately

@Dulanjala007 go to your extension installing path in ~/.vscode/extensions or %userprofile%\.vscode \extensions\ on windows.
Find svelte-vscode and in node_modules/svelte-language-server/dist/src/plugins/typescript/service.js remove line 121

            types: [path_1.resolve(sveltePkgInfo.path, 'types', 'runtime')],

@jasonlyu123 thank you very much...

Fix available in about 22 hours.

Was this page helpful?
0 / 5 - 0 ratings