diff --git a/docs/generated/packages/web/generators/application.json b/docs/generated/packages/web/generators/application.json index 7ddf805e10833..94d166cd45a83 100644 --- a/docs/generated/packages/web/generators/application.json +++ b/docs/generated/packages/web/generators/application.json @@ -98,6 +98,11 @@ "description": "Whether or not to configure the ESLint `parserOptions.project` option. We do not do this by default for lint performance reasons.", "default": false }, + "strict": { + "type": "boolean", + "description": "Creates an application with strict mode and strict type checking.", + "default": true + }, "standaloneConfig": { "description": "Split the project configuration into `/project.json` rather than including it inside workspace.json", "type": "boolean", diff --git a/packages/web/src/generators/application/application.spec.ts b/packages/web/src/generators/application/application.spec.ts index 9ae8f3f2b54d2..7c46f607846b0 100644 --- a/packages/web/src/generators/application/application.spec.ts +++ b/packages/web/src/generators/application/application.spec.ts @@ -546,6 +546,18 @@ describe('app', () => { expect(tree.exists('my-app/.babelrc')).toBeFalsy(); expect(tree.exists('my-app/.swcrc')).toBeTruthy(); }); + + it('should be strict by default', async () => { + await applicationGenerator(tree, { + name: 'my-app', + compiler: 'swc', + projectNameAndRootFormat: 'as-provided', + addPlugin: true, + } as Schema); + + const tsconfig = readJson(tree, 'my-app/tsconfig.json'); + expect(tsconfig.compilerOptions.strict).toBeTruthy(); + }); }); describe('setup web app with --bundler=vite', () => { diff --git a/packages/web/src/generators/application/application.ts b/packages/web/src/generators/application/application.ts index 74884c63e3ebc..8547f4c899d64 100644 --- a/packages/web/src/generators/application/application.ts +++ b/packages/web/src/generators/application/application.ts @@ -14,6 +14,7 @@ import { runTasksInSerial, TargetConfiguration, Tree, + updateJson, updateNxJson, updateProjectConfiguration, writeJson, @@ -109,6 +110,19 @@ function createApplicationFiles(tree: Tree, options: NormalizedSchema) { ); } } + updateJson( + tree, + joinPathFragments(options.appProjectRoot, 'tsconfig.json'), + (json) => { + return { + ...json, + compilerOptions: { + ...(json.compilerOptions || {}), + strict: options.strict, + }, + }; + } + ); } async function setupBundler(tree: Tree, options: NormalizedSchema) { @@ -534,6 +548,7 @@ async function normalizeOptions( compiler: options.compiler ?? 'babel', bundler: options.bundler ?? 'webpack', projectName: appProjectName, + strict: options.strict ?? true, appProjectRoot, e2eProjectRoot, e2eProjectName, diff --git a/packages/web/src/generators/application/schema.d.ts b/packages/web/src/generators/application/schema.d.ts index 8b67cced74891..e89949410127c 100644 --- a/packages/web/src/generators/application/schema.d.ts +++ b/packages/web/src/generators/application/schema.d.ts @@ -17,5 +17,6 @@ export interface Schema { linter?: Linter; standaloneConfig?: boolean; setParserOptionsProject?: boolean; + strict?: boolean; addPlugin?: boolean; } diff --git a/packages/web/src/generators/application/schema.json b/packages/web/src/generators/application/schema.json index 28e29cac5109d..a4b8798bf551c 100644 --- a/packages/web/src/generators/application/schema.json +++ b/packages/web/src/generators/application/schema.json @@ -101,6 +101,11 @@ "description": "Whether or not to configure the ESLint `parserOptions.project` option. We do not do this by default for lint performance reasons.", "default": false }, + "strict": { + "type": "boolean", + "description": "Creates an application with strict mode and strict type checking.", + "default": true + }, "standaloneConfig": { "description": "Split the project configuration into `/project.json` rather than including it inside workspace.json", "type": "boolean",