From a7e7c211b51a7c7577362f569fd39a2455e1bcc6 Mon Sep 17 00:00:00 2001 From: Charles Lyding <19598772+clydin@users.noreply.github.com> Date: Wed, 4 Nov 2020 19:55:38 -0500 Subject: [PATCH] feat(compiler-cli): add support for using TypeScript 4.1 (#39571) This change enables projects to be built with TypeScript 4.1. Support for TypeScript 4.0 is also retained. PR Close #39571 --- packages/compiler-cli/src/transformers/program.ts | 5 ++++- packages/compiler-cli/src/typescript_support.ts | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/compiler-cli/src/transformers/program.ts b/packages/compiler-cli/src/transformers/program.ts index d8af2c9f62..b7abbfc535 100644 --- a/packages/compiler-cli/src/transformers/program.ts +++ b/packages/compiler-cli/src/transformers/program.ts @@ -654,7 +654,10 @@ class AngularCompilerProgram implements Program { // - we cache all the files in the hostAdapter // - new new stubs use the exactly same imports/exports as the old once (we assert that in // hostAdapter.updateGeneratedFile). - if (tsStructureIsReused(tmpProgram) !== StructureIsReused.Completely) { + // TS 4.1+ stores the reuse state in the new program + const checkReuseProgram = + (ts.versionMajorMinor as string) === '4.0' ? tmpProgram : this._tsProgram; + if (tsStructureIsReused(checkReuseProgram) !== StructureIsReused.Completely) { throw new Error(`Internal Error: The structure of the program changed during codegen.`); } } diff --git a/packages/compiler-cli/src/typescript_support.ts b/packages/compiler-cli/src/typescript_support.ts index 4404033259..efdd34c8de 100644 --- a/packages/compiler-cli/src/typescript_support.ts +++ b/packages/compiler-cli/src/typescript_support.ts @@ -25,7 +25,7 @@ const MIN_TS_VERSION = '4.0.0'; * Note: this check is disabled in g3, search for * `angularCompilerOptions.disableTypeScriptVersionCheck` config param value in g3. */ -const MAX_TS_VERSION = '4.1.0'; +const MAX_TS_VERSION = '4.2.0'; /** * The currently used version of TypeScript, which can be adjusted for testing purposes using