From 565e0d96b55bf24016a23efc27fc6bd5e070ed6a Mon Sep 17 00:00:00 2001 From: Martin Probst Date: Thu, 29 Sep 2022 15:34:42 +0200 Subject: [PATCH] fix(compiler-cli): support hasInvalidatedResolutions. (#47585) The latest TypeScript compiler exposes the previously private field `hasInvalidatedResolutions`. That breaks Angular in the newer TS, because the new field would be required on DelegatingCompilerHost. However we cannot just add the field here, because it's not present in the older compiler. This change adds the field for delegation, which works at runtime because the field is present. It suppresses the compiler error using a `// @ts-expect-error`, which should be removed once Angular moves to a TSC version that includes this change. PR Close #47585 --- packages/compiler-cli/src/ngtsc/core/src/host.ts | 5 +++++ .../src/ngtsc/program_driver/src/ts_create_program_driver.ts | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/packages/compiler-cli/src/ngtsc/core/src/host.ts b/packages/compiler-cli/src/ngtsc/core/src/host.ts index 0bd331ac03b8c0..f537e2b73afe3d 100644 --- a/packages/compiler-cli/src/ngtsc/core/src/host.ts +++ b/packages/compiler-cli/src/ngtsc/core/src/host.ts @@ -68,6 +68,11 @@ export class DelegatingCompilerHost implements useCaseSensitiveFileNames = this.delegateMethod('useCaseSensitiveFileNames'); writeFile = this.delegateMethod('writeFile'); getModuleResolutionCache = this.delegateMethod('getModuleResolutionCache'); + // @ts-expect-error 'hasInvalidatedResolutions' is visible (and thus required here) in latest TSC + // main. It's already present, so the code works at runtime. + // TODO: remove this comment including the suppression once Angular uses a TSC version that + // includes this change (github.com/microsoft/TypeScript@a455955). + hasInvalidatedResolutions = this.delegateMethod('hasInvalidatedResolutions'); } /** diff --git a/packages/compiler-cli/src/ngtsc/program_driver/src/ts_create_program_driver.ts b/packages/compiler-cli/src/ngtsc/program_driver/src/ts_create_program_driver.ts index dfc87fa49caece..df7c59aed62553 100644 --- a/packages/compiler-cli/src/ngtsc/program_driver/src/ts_create_program_driver.ts +++ b/packages/compiler-cli/src/ngtsc/program_driver/src/ts_create_program_driver.ts @@ -52,6 +52,11 @@ export class DelegatingCompilerHost implements trace = this.delegateMethod('trace'); useCaseSensitiveFileNames = this.delegateMethod('useCaseSensitiveFileNames'); getModuleResolutionCache = this.delegateMethod('getModuleResolutionCache'); + // @ts-expect-error 'hasInvalidatedResolutions' is visible (and thus required here) in latest TSC + // main. It's already present, so the code works at runtime. + // TODO: remove this comment including the suppression once Angular uses a TSC version that + // includes this change (github.com/microsoft/TypeScript@a455955). + hasInvalidatedResolutions = this.delegateMethod('hasInvalidatedResolutions'); } /**