From 4bd4ec29bf4ddb9dd6d964294679a5f7f3c44c8b Mon Sep 17 00:00:00 2001 From: Craigory Coppola Date: Thu, 16 Nov 2023 16:21:48 -0500 Subject: [PATCH] fix(react): types should be in compilerOptions of tsconfig.spec.json (#20290) --- .../src/generators/application/application.spec.ts | 2 ++ .../application/lib/update-jest-config.ts | 14 ++++++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/packages/react/src/generators/application/application.spec.ts b/packages/react/src/generators/application/application.spec.ts index b25be440359fc..20e6ee1c45326 100644 --- a/packages/react/src/generators/application/application.spec.ts +++ b/packages/react/src/generators/application/application.spec.ts @@ -64,6 +64,8 @@ describe('app', () => { 'vite/client', 'node', 'vitest', + '@nx/react/typings/cssmodule.d.ts', + '@nx/react/typings/image.d.ts', ]); }); diff --git a/packages/react/src/generators/application/lib/update-jest-config.ts b/packages/react/src/generators/application/lib/update-jest-config.ts index cfb8c37877e83..3af0f138a5ff8 100644 --- a/packages/react/src/generators/application/lib/update-jest-config.ts +++ b/packages/react/src/generators/application/lib/update-jest-config.ts @@ -8,15 +8,17 @@ export function updateSpecConfig(host: Tree, options: NormalizedSchema) { } updateJson(host, `${options.appProjectRoot}/tsconfig.spec.json`, (json) => { - json.types = json.types || []; + const compilerOptions = json.compilerOptions ?? {}; + const types = compilerOptions.types ?? []; if (options.style === 'styled-jsx') { - json.types.push('@nx/react/typings/styled-jsx.d.ts'); + types.push('@nx/react/typings/styled-jsx.d.ts'); } - json.types = [ - ...json.types, + types.push( '@nx/react/typings/cssmodule.d.ts', - '@nx/react/typings/image.d.ts', - ]; + '@nx/react/typings/image.d.ts' + ); + compilerOptions.types = types; + json.compilerOptions = compilerOptions; return json; });