diff --git a/packages/compiler-cli/src/ngtools_api2.ts b/packages/compiler-cli/src/ngtools_api2.ts index bde6a9cf43..191736afff 100644 --- a/packages/compiler-cli/src/ngtools_api2.ts +++ b/packages/compiler-cli/src/ngtools_api2.ts @@ -60,6 +60,7 @@ export interface CompilerOptions extends ts.CompilerOptions { i18nInFile?: string; i18nInMissingTranslations?: 'error'|'warning'|'ignore'; preserveWhitespaces?: boolean; + disableTypeScriptVersionCheck?: boolean; } export interface CompilerHost extends ts.CompilerHost { diff --git a/packages/compiler-cli/src/transformers/api.ts b/packages/compiler-cli/src/transformers/api.ts index b428f8fe0f..c257d301d7 100644 --- a/packages/compiler-cli/src/transformers/api.ts +++ b/packages/compiler-cli/src/transformers/api.ts @@ -132,6 +132,9 @@ export interface CompilerOptions extends ts.CompilerOptions { // position. disableExpressionLowering?: boolean; + // Disable TypeScript Version Check. + disableTypeScriptVersionCheck?: boolean; + // Locale of the application i18nOutLocale?: string; // Export format (xlf, xlf2 or xmb) diff --git a/packages/compiler-cli/src/transformers/program.ts b/packages/compiler-cli/src/transformers/program.ts index 1e1864773c..9970fb692e 100644 --- a/packages/compiler-cli/src/transformers/program.ts +++ b/packages/compiler-cli/src/transformers/program.ts @@ -71,10 +71,11 @@ class AngularCompilerProgram implements Program { rootNames: ReadonlyArray, private options: CompilerOptions, private host: CompilerHost, oldProgram?: Program) { this.rootNames = [...rootNames]; - const [major, minor] = ts.version.split('.'); - Number(major) > 2 || (Number(major) === 2 && Number(minor) >= 4) || - userError('The Angular Compiler requires TypeScript >= 2.4.'); + if (ts.version < '2.4.2' || (ts.version >= '2.7.0' && !options.disableTypeScriptVersionCheck)) { + throw new Error( + `The Angular Compiler requires TypeScript >=2.4.2 and <2.7 but ${ts.version} was found instead.`); + } this.oldTsProgram = oldProgram ? oldProgram.getTsProgram() : undefined; if (oldProgram) {