Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/language-server/public/sink.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare module 'react' {}
16 changes: 14 additions & 2 deletions packages/language-server/src/plugins/typescript/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,17 @@ export function createLanguageService(
);
}

configJson.compilerOptions = configJson.compilerOptions || {};
// Reroute react paths to a sink with no typings to prevent conflicts between the
// svelte2tsx JSX typings and react's JSX typings.
// This may happen if a node module has (in)directly installed/imported react's types.
if (!configJson.compilerOptions.paths?.react) {
configJson.paths = configJson.paths || {};
configJson.paths.react = [
ts.sys.resolvePath(resolve(__dirname, '../../../../public/sink.d.ts')),
];
}

const parsedConfig = ts.parseJsonConfigFileContent(
configJson,
ts.sys,
Expand All @@ -194,8 +205,9 @@ export function createLanguageService(
const files = parsedConfig.fileNames;

const sveltePkgInfo = getPackageInfo('svelte', workspacePath || process.cwd());
const types = (parsedConfig.options?.types ?? [])
.concat(resolve(sveltePkgInfo.path, 'types', 'runtime'));
const types = (parsedConfig.options?.types ?? []).concat(
resolve(sveltePkgInfo.path, 'types', 'runtime'),
);
const compilerOptions: ts.CompilerOptions = {
...parsedConfig.options,
types,
Expand Down