Skip to content

Commit 438e2eb

Browse files
alan-agius4mgechev
authored andcommitted
feat(@schematics/angular): add strict compiler option to workspace tsconfig (#14905)
Closes #14694
1 parent 10493a2 commit 438e2eb

File tree

5 files changed

+26
-2
lines changed

5 files changed

+26
-2
lines changed

packages/schematics/angular/workspace/files/tsconfig.json.template

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22
"compileOnSave": false,
33
"compilerOptions": {
44
"baseUrl": "./",
5-
"outDir": "./dist/out-tsc",
5+
"outDir": "./dist/out-tsc",<% if (strict) { %>
6+
"noImplicitAny": true,
7+
"noImplicitReturns": true,
8+
"noImplicitThis": true,
9+
"noFallthroughCasesInSwitch": true,
10+
"strictNullChecks": true,<% } %>
611
"sourceMap": true,
712
"declaration": false,
813
"downlevelIteration": true,

packages/schematics/angular/workspace/index_spec.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,16 @@ describe('Workspace Schematic', () => {
7171
expect(files).not.toContain('/tslint.json');
7272
expect(files).not.toContain('/.editorconfig');
7373
});
74+
75+
it('should not add strict compiler options when false', async () => {
76+
const tree = await schematicRunner.runSchematicAsync('workspace', { ...defaultOptions, strict: false }).toPromise();
77+
const { compilerOptions } = JSON.parse(tree.readContent('/tsconfig.json'));
78+
expect(compilerOptions.strictNullChecks).not.toBeDefined();
79+
});
80+
81+
it('should not add strict compiler options when true', async () => {
82+
const tree = await schematicRunner.runSchematicAsync('workspace', { ...defaultOptions, strict: true }).toPromise();
83+
const { compilerOptions } = JSON.parse(tree.readContent('/tsconfig.json'));
84+
expect(compilerOptions.strictNullChecks).toBe(true);
85+
});
7486
});

packages/schematics/angular/workspace/schema.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@
3131
"type": "boolean",
3232
"default": false,
3333
"x-user-analytics": 14
34+
},
35+
"strict": {
36+
"description": "Creates a workspace with stricter TypeScript compiler options.",
37+
"type": "boolean",
38+
"default": false
3439
}
3540
},
3641
"required": [

tests/legacy-cli/e2e/tests/build/platform-server.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ export default async function () {
1010
const veEnabled = argv['ve'];
1111

1212
await ng('add', '@nguniversal/express-engine', '--client-project', 'test-project');
13+
// todo remove once https://github.com/angular/universal/pull/1229 is landed
14+
await silentNpm('install', '@types/express', '--save-dev');
1315

1416
await updateJsonFile('package.json', packageJson => {
1517
const dependencies = packageJson['dependencies'];

tests/legacy-cli/e2e/tests/misc/browsers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export default async function () {
3939
await replaceInFile(
4040
'e2e/src/app.e2e-spec.ts',
4141
'await browser.manage().logs().get(logging.Type.BROWSER)',
42-
'[]',
42+
'[] as any',
4343
);
4444

4545
// Workaround defect in getText WebDriver implementation for Safari/Edge

0 commit comments

Comments
 (0)