fix: check if sysFormatDiagnosticsHost is defined (#44344)

* fix: check if sysFormatDiagnosticsHost is defined

* improve types
This commit is contained in:
Kitson Kelly
2021-06-04 10:05:48 +10:00
committed by GitHub
parent cec2fda9a5
commit 4b235eca17

View File

@@ -1,16 +1,16 @@
/*@internal*/
namespace ts {
const sysFormatDiagnosticsHost: FormatDiagnosticsHost = sys ? {
const sysFormatDiagnosticsHost: FormatDiagnosticsHost | undefined = sys ? {
getCurrentDirectory: () => sys.getCurrentDirectory(),
getNewLine: () => sys.newLine,
getCanonicalFileName: createGetCanonicalFileName(sys.useCaseSensitiveFileNames)
} : undefined!; // TODO: GH#18217
} : undefined;
/**
* Create a function that reports error by writing to the system and handles the formating of the diagnostic
*/
export function createDiagnosticReporter(system: System, pretty?: boolean): DiagnosticReporter {
const host: FormatDiagnosticsHost = system === sys ? sysFormatDiagnosticsHost : {
const host: FormatDiagnosticsHost = system === sys && sysFormatDiagnosticsHost ? sysFormatDiagnosticsHost : {
getCurrentDirectory: () => system.getCurrentDirectory(),
getNewLine: () => system.newLine,
getCanonicalFileName: createGetCanonicalFileName(system.useCaseSensitiveFileNames),