From 55fad6f48093515262c141ecd4d72e87bd02e891 Mon Sep 17 00:00:00 2001 From: Matthias Osswald Date: Mon, 10 Feb 2025 19:55:29 +0100 Subject: [PATCH] refactor: Improve type loading - Don't include irrelevant types in the type loading process - Ensure that modules from sap.ui.core are not looked up within the linted project. This happened as there was no mapping for the sap/ui/core namespace and TypeScript first tried to load the module relative to the requesting module and only afterwards used the dts file from "types". --- src/linter/ui5Types/host.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/linter/ui5Types/host.ts b/src/linter/ui5Types/host.ts index fa934e9c..2b1e7f53 100644 --- a/src/linter/ui5Types/host.ts +++ b/src/linter/ui5Types/host.ts @@ -57,12 +57,12 @@ function addSapui5TypesMappingToCompilerOptions( // - When linting a framework library, the corresponding types should be loaded by default as they // might not get loaded by the compiler otherwise, as the actual sources are available in the project. options.types?.push(dtsPath); - } else { - // For other framework libraries we can add a paths mapping to load them on demand - const mappingNamespace = libraryNamespace + "/*"; - const pathsEntry = paths[mappingNamespace] ?? (paths[mappingNamespace] = []); - pathsEntry.push(dtsPath); } + // In every case, add a paths mapping to load them on demand and ensure loading them + // when the framework library itself is linted + const mappingNamespace = libraryNamespace + "/*"; + const pathsEntry = paths[mappingNamespace] ?? (paths[mappingNamespace] = []); + pathsEntry.push(dtsPath); }); } @@ -84,6 +84,11 @@ export async function createVirtualLanguageServiceHost( const typePackages = new Set(["@sapui5/types"]); await collectTransitiveDependencies("@sapui5/types", typePackages); + + // Remove dependencies that are not needed for UI5 linter type checking: + typePackages.delete("@types/three"); // Used in sap.ui.vk, but is not needed for linter checks. + typePackages.delete("@types/offscreencanvas"); // Used by @types/three + typePackages.forEach((pkgName) => { addPathMappingForPackage(pkgName, typePathMappings); });