Skip to content

Commit f46e8bd

Browse files
JeanMecheleonsenft
authored andcommitted
refactor(compiler): remove fullTemplateTypeCheck compiler option.
The option was deprecated back in v13. Users should use `strictTemplates: true`.
1 parent 2615f35 commit f46e8bd

File tree

8 files changed

+46
-21
lines changed

8 files changed

+46
-21
lines changed

packages/compiler-cli/src/ngtsc/core/api/src/public_options.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ export interface TypeCheckingOptions {
102102
*
103103
* This flag is a superset of the deprecated `fullTemplateTypeCheck` option.
104104
*
105-
* Defaults to `false`, even if "fullTemplateTypeCheck" is `true`.
105+
* Defaults to `true`
106106
*/
107107
strictTemplates?: boolean;
108108

packages/compiler-cli/src/ngtsc/core/src/compiler.ts

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
* found in the LICENSE file at https://angular.dev/license
77
*/
88

9-
import {R3Identifiers} from '@angular/compiler';
109
import ts from 'typescript';
1110

1211
import {
@@ -65,10 +64,10 @@ import {
6564
import {SemanticSymbol} from '../../incremental/semantic_graph';
6665
import {generateAnalysis, IndexedComponent, IndexingContext} from '../../indexer';
6766
import {
68-
DirectiveResources,
6967
CompoundMetadataReader,
7068
CompoundMetadataRegistry,
7169
DirectiveMeta,
70+
DirectiveResources,
7271
DtsMetadataReader,
7372
ExportedProviderStatusResolver,
7473
HostDirectivesResolver,
@@ -106,8 +105,8 @@ import {
106105
DecoratorHandler,
107106
DtsTransformRegistry,
108107
ivyTransformFactory,
109-
TraitCompiler,
110108
signalMetadataTransform,
109+
TraitCompiler,
111110
} from '../../transform';
112111
import {TemplateTypeCheckerImpl} from '../../typecheck';
113112
import {OptimizeFor, TemplateTypeChecker, TypeCheckingConfig} from '../../typecheck/api';
@@ -124,10 +123,10 @@ import {SourceFileValidator} from '../../validation';
124123
import {Xi18nContext} from '../../xi18n';
125124
import {DiagnosticCategoryLabel, NgCompilerAdapter, NgCompilerOptions} from '../api';
126125

127-
import {coreVersionSupportsFeature} from './feature_detection';
128-
import {angularJitApplicationTransform} from '../../transform/jit';
129-
import {untagAllTsFiles} from '../../shims';
130126
import {DOC_PAGE_BASE_URL} from '../../diagnostics/src/error_details_base_url';
127+
import {untagAllTsFiles} from '../../shims';
128+
import {angularJitApplicationTransform} from '../../transform/jit';
129+
import {coreVersionSupportsFeature} from './feature_detection';
131130

132131
/**
133132
* State information about a compilation which is only generated once some data is requested from
@@ -658,7 +657,7 @@ export class NgCompiler {
658657
if (templateSemanticsChecker !== null) {
659658
diagnostics.push(...templateSemanticsChecker.getDiagnosticsForComponent(component));
660659
}
661-
if (this.options.strictTemplates && extendedTemplateChecker !== null) {
660+
if (this.strictTemplates && extendedTemplateChecker !== null) {
662661
diagnostics.push(...extendedTemplateChecker.getDiagnosticsForComponent(component));
663662
}
664663
} catch (err: unknown) {
@@ -1037,21 +1036,28 @@ export class NgCompiler {
10371036
});
10381037
}
10391038

1039+
/**
1040+
* strictTemplate is `true` by default.
1041+
* Explicit opt-out is required to disable strictness
1042+
*/
1043+
private get strictTemplates(): boolean {
1044+
return this.options.strictTemplates !== false;
1045+
}
1046+
10401047
private get fullTemplateTypeCheck(): boolean {
10411048
// Determine the strictness level of type checking based on compiler options. As
10421049
// `strictTemplates` is a superset of `fullTemplateTypeCheck`, the former implies the latter.
10431050
// Also see `verifyCompatibleTypeCheckOptions` where it is verified that `fullTemplateTypeCheck`
10441051
// is not disabled when `strictTemplates` is enabled.
1045-
const strictTemplates = !!this.options.strictTemplates;
1046-
return strictTemplates || !!this.options.fullTemplateTypeCheck;
1052+
return this.strictTemplates || !!this.options.fullTemplateTypeCheck;
10471053
}
10481054

10491055
private getTypeCheckingConfig(): TypeCheckingConfig {
10501056
// Determine the strictness level of type checking based on compiler options. As
10511057
// `strictTemplates` is a superset of `fullTemplateTypeCheck`, the former implies the latter.
10521058
// Also see `verifyCompatibleTypeCheckOptions` where it is verified that `fullTemplateTypeCheck`
10531059
// is not disabled when `strictTemplates` is enabled.
1054-
const strictTemplates = !!this.options.strictTemplates;
1060+
const strictTemplates = this.strictTemplates;
10551061

10561062
const useInlineTypeConstructors = this.programDriver.supportsInlineOperations;
10571063
const checkTwoWayBoundEvents = this.options['_checkTwoWayBoundEvents'] ?? false;
@@ -1278,7 +1284,7 @@ export class NgCompiler {
12781284
}),
12791285
);
12801286
}
1281-
if (this.options.strictTemplates && extendedTemplateChecker !== null) {
1287+
if (this.strictTemplates && extendedTemplateChecker !== null) {
12821288
diagnostics.push(
12831289
...compilation.traitCompiler.runAdditionalChecks(sf, (clazz, handler) => {
12841290
return handler.extendedTemplateCheck?.(clazz, extendedTemplateChecker) || null;
@@ -1765,7 +1771,7 @@ function getR3SymbolsFile(program: ts.Program): ts.SourceFile | null {
17651771
function* verifyCompatibleTypeCheckOptions(
17661772
options: NgCompilerOptions,
17671773
): Generator<ts.Diagnostic, void, void> {
1768-
if (options.fullTemplateTypeCheck === false && options.strictTemplates === true) {
1774+
if (options.fullTemplateTypeCheck === false && options.strictTemplates !== false) {
17691775
yield makeConfigDiagnostic({
17701776
category: ts.DiagnosticCategory.Error,
17711777
code: ErrorCode.CONFIG_STRICT_TEMPLATES_IMPLIES_FULL_TEMPLATE_TYPECHECK,
@@ -1777,7 +1783,7 @@ the latter can not be explicitly disabled.
17771783
17781784
One of the following actions is required:
17791785
1. Remove the "fullTemplateTypeCheck" option.
1780-
2. Remove "strictTemplates" or set it to 'false'.
1786+
2. Set "strictTemplates" to 'false'.
17811787
17821788
More information about the template type checking compiler options can be found in the documentation:
17831789
${DOC_PAGE_BASE_URL}/tools/cli/template-typecheck

packages/compiler-cli/test/compliance/codegen/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ jasmine_test(
1717
name = "codegen",
1818
data = [
1919
":test_lib",
20+
"//packages/animations:npm_package",
2021
"//packages/compiler-cli/test/compliance/test_cases",
2122
"//packages/core:npm_package",
2223
],

packages/compiler-cli/test/compliance/test_cases/r3_compiler_compliance/components_and_directives/GOLDEN_PARTIAL.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "0.0.0-PLACEHOLDE
7676
}]
7777
}] });
7878
class MyForwardPipe {
79-
transform() { }
79+
transform(param) { }
8080
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "0.0.0-PLACEHOLDER", ngImport: i0, type: MyForwardPipe, deps: [], target: i0.ɵɵFactoryTarget.Pipe });
8181
static ɵpipe = i0.ɵɵngDeclarePipe({ minVersion: "14.0.0", version: "0.0.0-PLACEHOLDER", ngImport: i0, type: MyForwardPipe, isStandalone: false, name: "my_forward_pipe" });
8282
}

packages/compiler-cli/test/compliance/test_cases/r3_compiler_compliance/components_and_directives/forward_referenced_pipe.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {Component, NgModule, Pipe} from '@angular/core';
1+
import { Component, NgModule, Pipe } from '@angular/core';
22

33
@Component({
44
selector: 'host-binding-comp',
@@ -15,7 +15,7 @@ export class HostBindingComp {
1515
standalone: false
1616
})
1717
class MyForwardPipe {
18-
transform() {}
18+
transform(param:unknown) {}
1919
}
2020

2121
@NgModule({declarations: [HostBindingComp, MyForwardPipe]})

packages/compiler-cli/test/compliance/test_helpers/compile_test.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,11 @@ export function compileTest(
6262
): CompileResult {
6363
const rootDir = getRootDirectory(fs);
6464
const outDir = getBuildOutputDirectory(fs);
65-
const options = getOptions(rootDir, outDir, compilerOptions, angularCompilerOptions);
65+
const options = getOptions(rootDir, outDir, compilerOptions, {
66+
...angularCompilerOptions,
67+
// TODO: Do we want to enable strictTemplates for compliance tests?
68+
strictTemplates: false,
69+
});
6670
const rootNames = files.map((f) => fs.resolve(f));
6771
const host = new NgtscTestCompilerHost(fs, options);
6872
const {diagnostics, emitResult} = performCompilation({rootNames, host, options});

packages/compiler-cli/test/ngtsc/env.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@
66
* found in the LICENSE file at https://angular.dev/license
77
*/
88

9+
import ts from 'typescript';
910
import {
11+
createCompilerHost,
12+
createProgram,
1013
CustomTransformers,
1114
defaultGatherDiagnostics,
1215
Program,
13-
createCompilerHost,
14-
createProgram,
1516
} from '../../index';
1617
import {DocEntry} from '../../src/ngtsc/docs';
1718
import * as api from '../../src/transformers/api';
18-
import ts from 'typescript';
1919

2020
import {mainXi18n} from '../../src/extract_i18n';
2121
import {main, mainDiagnosticsForTest, readNgcCommandLineAndConfiguration} from '../../src/main';
@@ -229,6 +229,11 @@ export class NgtscTestEnvironment {
229229
compilerOptions?: TsCompilerOptions,
230230
files?: string[],
231231
): void {
232+
// TODO: all tests should have template that pass strictness
233+
if (!('strictTemplates' in extraOpts)) {
234+
extraOpts['strictTemplates'] = false;
235+
}
236+
232237
let tsconfig: {[key: string]: any} = {
233238
extends: './tsconfig-base.json',
234239
angularCompilerOptions: extraOpts,

packages/compiler-cli/test/ngtsc/template_typecheck_spec.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4178,6 +4178,7 @@ runInEachFileSystem(() => {
41784178

41794179
it('should error if "extendedDiagnostics.defaultCategory" is set to an unknown value', () => {
41804180
env.tsconfig({
4181+
strictTemplates: true,
41814182
extendedDiagnostics: {
41824183
defaultCategory: 'does-not-exist',
41834184
},
@@ -4199,6 +4200,7 @@ suppress
41994200
});
42004201
it('should not error if "extendedDiagnostics.defaultCategory" is set to a known value', () => {
42014202
env.tsconfig({
4203+
strictTemplates: true,
42024204
extendedDiagnostics: {
42034205
defaultCategory: DiagnosticCategoryLabel.Error,
42044206
},
@@ -4210,6 +4212,7 @@ suppress
42104212

42114213
it('should error if "extendedDiagnostics.checks" contains an unknown check', () => {
42124214
env.tsconfig({
4215+
strictTemplates: true,
42134216
extendedDiagnostics: {
42144217
checks: {
42154218
doesNotExist: DiagnosticCategoryLabel.Error,
@@ -4225,6 +4228,7 @@ suppress
42254228
});
42264229
it('should not error if "extendedDiagnostics.checks" contains all known checks', () => {
42274230
env.tsconfig({
4231+
strictTemplates: true,
42284232
extendedDiagnostics: {
42294233
checks: {
42304234
[invalidBananaInBoxFactory.name]: DiagnosticCategoryLabel.Error,
@@ -4238,6 +4242,7 @@ suppress
42384242

42394243
it('should error if "extendedDiagnostics.checks" contains an unknown diagnostic category', () => {
42404244
env.tsconfig({
4245+
strictTemplates: true,
42414246
extendedDiagnostics: {
42424247
checks: {
42434248
[invalidBananaInBoxFactory.name]: 'does-not-exist',
@@ -4261,6 +4266,7 @@ suppress
42614266
});
42624267
it('should not error if "extendedDiagnostics.checks" contains all known diagnostic categories', () => {
42634268
env.tsconfig({
4269+
strictTemplates: true,
42644270
extendedDiagnostics: {
42654271
checks: {
42664272
[invalidBananaInBoxFactory.name]: DiagnosticCategoryLabel.Error,
@@ -7044,6 +7050,7 @@ suppress
70447050

70457051
it('should allow the content projection diagnostic to be disabled individually', () => {
70467052
env.tsconfig({
7053+
strictTemplates: true,
70477054
extendedDiagnostics: {
70487055
checks: {
70497056
controlFlowPreventingContentProjection: DiagnosticCategoryLabel.Suppress,
@@ -7082,6 +7089,7 @@ suppress
70827089

70837090
it('should allow the content projection diagnostic to be disabled via `defaultCategory`', () => {
70847091
env.tsconfig({
7092+
strictTemplates: true,
70857093
extendedDiagnostics: {
70867094
defaultCategory: DiagnosticCategoryLabel.Suppress,
70877095
},
@@ -8232,6 +8240,7 @@ suppress
82328240

82338241
it('should be able to opt out for checking for unused imports via the tsconfig', () => {
82348242
env.tsconfig({
8243+
strictTemplates: true,
82358244
extendedDiagnostics: {
82368245
checks: {
82378246
unusedStandaloneImports: DiagnosticCategoryLabel.Suppress,

0 commit comments

Comments
 (0)