diff --git a/src/server/typingsInstaller/typingsInstaller.ts b/src/server/typingsInstaller/typingsInstaller.ts index fe629b353b7..a3b96a4e02e 100644 --- a/src/server/typingsInstaller/typingsInstaller.ts +++ b/src/server/typingsInstaller/typingsInstaller.ts @@ -45,7 +45,7 @@ namespace ts.server.typingsInstaller { entries: MapLike; } - function loadTypeDeclarationTimestampFile(typeDeclarationTimestampFilePath: string, host: InstallTypingHost, log: Log): Map { + function loadTypeDeclarationTimestampFile(typeDeclarationTimestampFilePath: string, host: InstallTypingHost, log: Log): MapLike { const fileExists = host.fileExists(typeDeclarationTimestampFilePath); if (!fileExists) { if (log.isEnabled()) { @@ -55,21 +55,21 @@ namespace ts.server.typingsInstaller { try { if (fileExists) { const content = JSON.parse(host.readFile(typeDeclarationTimestampFilePath)); - return createMapFromTemplate(content.entries); + return content.entries; } else { host.writeFile(typeDeclarationTimestampFilePath, "{}"); if (log.isEnabled()) { log.writeLine("Type declaration timestamp file was created."); } - return createMap(); + return {}; } } catch (e) { if (log.isEnabled()) { log.writeLine(`Error when loading type declaration timestamp file '${typeDeclarationTimestampFilePath}': ${(e).message}, ${(e).stack}`); } - return createMap(); + return {}; } } @@ -108,7 +108,7 @@ namespace ts.server.typingsInstaller { private readonly projectWatchers: Map = createMap(); private safeList: JsTyping.SafeList | undefined; readonly pendingRunRequests: PendingRequest[] = []; - private typeDeclarationTimestamps: Map = createMap(); + private typeDeclarationTimestamps: MapLike = {}; private installRunCount = 1; private inFlightRequestCount = 0; @@ -258,14 +258,14 @@ namespace ts.server.typingsInstaller { if (this.log.isEnabled()) { this.log.writeLine(`Adding entry into typings cache: '${packageName}' => '${typingFile}'`); } - if (this.typeDeclarationTimestamps.get(key) === undefined) { + if (getProperty(this.typeDeclarationTimestamps, key) === undefined) { // getModifiedTime is only undefined if we were to use the ChakraHost, but we never do in this scenario // defaults to old behavior of never updating if we ever use a host without getModifiedTime in the future const timestamp = this.installTypingHost.getModifiedTime === undefined ? Date.now() : this.installTypingHost.getModifiedTime(typingFile).getTime(); - this.typeDeclarationTimestamps.set(key, timestamp); + this.typeDeclarationTimestamps[key] = timestamp; } // timestamp guaranteed to not be undefined by above check - const newTyping: JsTyping.CachedTyping = { typingLocation: typingFile, timestamp: this.typeDeclarationTimestamps.get(key) }; + const newTyping: JsTyping.CachedTyping = { typingLocation: typingFile, timestamp: getProperty(this.typeDeclarationTimestamps, key) }; this.packageNameToTypingLocation.set(packageName, newTyping); } } @@ -365,11 +365,11 @@ namespace ts.server.typingsInstaller { this.missingTypingsSet.set(packageName, true); continue; } - if (!this.packageNameToTypingLocation.has(packageName)) { - const newTyping: JsTyping.CachedTyping = { typingLocation: typingFile, timestamp: Date.now() }; - this.packageNameToTypingLocation.set(packageName, newTyping); - this.typeDeclarationTimestamps.set(packageName, Date.now()); - } + + const newTimestamp = Date.now(); + const newTyping: JsTyping.CachedTyping = { typingLocation: typingFile, timestamp: newTimestamp }; + this.packageNameToTypingLocation.set(packageName, newTyping); + this.typeDeclarationTimestamps[packageName] = newTimestamp; installedTypingFiles.push(typingFile); } if (this.log.isEnabled()) {