From 167f954ec7cf456238cad4f2006fb330c53bba8e Mon Sep 17 00:00:00 2001 From: Andrew Casey Date: Mon, 27 Apr 2020 16:18:39 -0700 Subject: [PATCH] Handle undefined in indent helper (#38217) * Handle undefined in indent helper Telemetry shows that it's called with undefined (probably `stderr` in an error scenario?). * Add undefined to parameter type --- src/typingsInstaller/nodeTypingsInstaller.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/typingsInstaller/nodeTypingsInstaller.ts b/src/typingsInstaller/nodeTypingsInstaller.ts index 56b490e709d..ab050fd60bf 100644 --- a/src/typingsInstaller/nodeTypingsInstaller.ts +++ b/src/typingsInstaller/nodeTypingsInstaller.ts @@ -246,7 +246,9 @@ namespace ts.server.typingsInstaller { const installer = new NodeTypingsInstaller(globalTypingsCacheLocation!, typingSafeListLocation!, typesMapLocation!, npmLocation, validateDefaultNpmLocation, /*throttleLimit*/5, log); // TODO: GH#18217 installer.listen(); - function indent(newline: string, str: string): string { - return `${newline} ` + str.replace(/\r?\n/, `${newline} `); + function indent(newline: string, str: string | undefined): string { + return str && str.length + ? `${newline} ` + str.replace(/\r?\n/, `${newline} `) + : ""; } }