diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index c8e6353da08..e00d47d1a66 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -1633,7 +1633,7 @@ namespace ts { text = readFile(fileName); } catch (e) { - return createCompilerDiagnostic(Diagnostics.Cannot_read_file_0_Colon_1, fileName, e.message); + return createCompilerDiagnostic(Diagnostics.Cannot_read_file_0_Colon_1, fileName, (e as Error).message); } return text === undefined ? createCompilerDiagnostic(Diagnostics.Cannot_read_file_0, fileName) : text; } diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 8d4efc3e941..0fad9661fb5 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -83,7 +83,7 @@ namespace ts { performance.measure("I/O Read", "beforeIORead", "afterIORead"); } catch (e) { - if (onError) { + if (onError && e instanceof Error) { onError(e.message); } text = ""; @@ -121,7 +121,7 @@ namespace ts { performance.measure("I/O Write", "beforeIOWrite", "afterIOWrite"); } catch (e) { - if (onError) { + if (onError && e instanceof Error) { onError(e.message); } } diff --git a/src/compiler/sys.ts b/src/compiler/sys.ts index 0b3080138d6..53bd670c4f6 100644 --- a/src/compiler/sys.ts +++ b/src/compiler/sys.ts @@ -1242,7 +1242,7 @@ namespace ts { _fs.mkdirSync(directoryName); } catch (e) { - if (e.code !== "EEXIST") { + if ((e as {code: string}).code !== "EEXIST") { // Failed for some other reason (access denied?); still throw throw e; } @@ -1312,7 +1312,7 @@ namespace ts { const modulePath = resolveJSModule(moduleName, baseDir, nodeSystem); return { module: require(modulePath), modulePath, error: undefined }; } - catch (error) { + catch (error: any) { return { module: undefined, modulePath: undefined, error }; } } diff --git a/src/compiler/watch.ts b/src/compiler/watch.ts index ab7c06ee482..3e4e6439af7 100644 --- a/src/compiler/watch.ts +++ b/src/compiler/watch.ts @@ -291,7 +291,7 @@ namespace ts { performance.measure("I/O Read", "beforeIORead", "afterIORead"); } catch (e) { - if (onError) { + if (onError && e instanceof Error) { onError(e.message); } text = ""; @@ -317,7 +317,7 @@ namespace ts { readDirectory: maybeBind(host, host.readDirectory), }; - function writeFile(fileName: string, text: string, writeByteOrderMark: boolean, onError: (message: string) => void) { + function writeFile(fileName: string, text: string, writeByteOrderMark: boolean, onError?: (message: string) => void) { try { performance.mark("beforeIOWrite"); @@ -336,7 +336,7 @@ namespace ts { performance.measure("I/O Write", "beforeIOWrite", "afterIOWrite"); } catch (e) { - if (onError) { + if (onError && e instanceof Error) { onError(e.message); } } diff --git a/src/services/shims.ts b/src/services/shims.ts index 14f6a61e747..97143fa22a7 100644 --- a/src/services/shims.ts +++ b/src/services/shims.ts @@ -451,7 +451,7 @@ namespace ts { return JSON.parse(diagnosticMessagesJson); } catch (e) { - this.log(e.description || "diagnosticMessages.generated.json has invalid JSON format"); + this.log((e as { description?: string }).description || "diagnosticMessages.generated.json has invalid JSON format"); return null; } /* eslint-enable no-null/no-null */ @@ -579,7 +579,7 @@ namespace ts { const result = simpleForwardCall(logger, actionDescription, action, logPerformance); return returnJson ? JSON.stringify({ result }) : result as T; } - catch (err) { + catch (err: any) { if (err instanceof OperationCanceledException) { return JSON.stringify({ canceled: true }); } @@ -1283,7 +1283,7 @@ namespace ts { const languageService = createLanguageService(hostAdapter, this.documentRegistry, /*syntaxOnly*/ false); return new LanguageServiceShimObject(this, host, languageService); } - catch (err) { + catch (err: any) { logInternalError(host, err); throw err; } @@ -1293,7 +1293,7 @@ namespace ts { try { return new ClassifierShimObject(this, logger); } - catch (err) { + catch (err: any) { logInternalError(logger, err); throw err; } @@ -1304,7 +1304,7 @@ namespace ts { const adapter = new CoreServicesShimHostAdapter(host); return new CoreServicesShimObject(this, host, adapter); } - catch (err) { + catch (err: any) { logInternalError(host, err); throw err; }