diff --git a/e2e/harmony/tsconfig-env-mismatch.e2e.ts b/e2e/harmony/tsconfig-env-mismatch.e2e.ts index b87c34566c61..e8b6fe14315a 100644 --- a/e2e/harmony/tsconfig-env-mismatch.e2e.ts +++ b/e2e/harmony/tsconfig-env-mismatch.e2e.ts @@ -41,7 +41,9 @@ describe('tsconfig env mismatch between check-types and build', function () { before(() => { helper.scopeHelper.setWorkspaceWithRemoteScope(); - // Create permissive tsconfig (no strict mode) + // Create permissive tsconfig (strict mode explicitly off). + // strict must be set explicitly because TS 6 changed the default from false to true, + // and this fixture was relying on the TS 5 default. const permissiveTsconfig = JSON.stringify( { compilerOptions: { @@ -55,7 +57,7 @@ describe('tsconfig env mismatch between check-types and build', function () { moduleResolution: 'node', esModuleInterop: true, outDir: './dist', - // No strict mode - permissive + strict: false, }, exclude: ['artifacts', 'public', 'dist', 'node_modules'], }, diff --git a/scopes/typescript/typescript/typescript.main.runtime.ts b/scopes/typescript/typescript/typescript.main.runtime.ts index 3146deedf61e..1d4bb6698e1f 100644 --- a/scopes/typescript/typescript/typescript.main.runtime.ts +++ b/scopes/typescript/typescript/typescript.main.runtime.ts @@ -130,6 +130,26 @@ export class TypescriptMain { const configMutator = new TypescriptConfigMutator(options); const transformerContext: TsConfigTransformContext = {}; const afterMutation = runTransformersWithContext(configMutator.clone(), transformers, transformerContext); + // TS 6 flipped several defaults and turned legacy options into hard errors. + // Shipped env tsconfigs must stay valid for TS 5.x consumers, so patch the raw tsconfig + // at runtime when the loaded compiler is actually TS 6+ — preserving TS 5 behavior. + const tsMajor = parseInt(tsModule.version?.split('.')[0] || '0', 10); + const tsconfig = afterMutation.raw.tsconfig; + const compilerOptions = tsconfig?.compilerOptions; + if (tsMajor >= 6 && compilerOptions) { + if (!compilerOptions.ignoreDeprecations) compilerOptions.ignoreDeprecations = '6.0'; + if (compilerOptions.noUncheckedSideEffectImports === undefined) + compilerOptions.noUncheckedSideEffectImports = false; + // strict and types: don't inject when the tsconfig extends a base — the base may + // already set these, and an explicit value here would silently override the inherited one. + if (!tsconfig.extends) { + if (compilerOptions.strict === undefined) compilerOptions.strict = false; + // TS 6 stopped auto-discovering @types/* packages (types defaults to []). + // Seed the types every Bit env installs — @types/node universally and @types/jest + // (provides describe/it/expect globals). React env excludes @types/mocha, so don't seed it. + if (compilerOptions.types === undefined) compilerOptions.types = ['node', 'jest']; + } + } const afterMutationWithoutTsconfig = { ...afterMutation.raw, tsconfig: '' }; return new TypescriptCompiler( diff --git a/tsconfig.json b/tsconfig.json index bca37334c636..26c1125bff5a 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -6,6 +6,9 @@ "strict": true, "moduleResolution": "node", "module": "commonjs", + "ignoreDeprecations": "6.0", + "noUncheckedSideEffectImports": false, + "types": ["node", "mocha", "chai", "jest"], "target": "es2015", "skipLibCheck": true, "noImplicitAny": false, diff --git a/workspace.jsonc b/workspace.jsonc index a4e4228cad4a..c4a39797ab62 100644 --- a/workspace.jsonc +++ b/workspace.jsonc @@ -397,6 +397,7 @@ "@types/lodash.flatten": "4.4.6", "@types/lodash.head": "4.0.6", "@types/mdx-js__react": "1.5.5", + "@types/jest": "29.5.14", "@types/memoizee": "0.4.5", "@types/mime": "2.0.3", "@types/mini-css-extract-plugin": "2.2.0", @@ -642,7 +643,7 @@ "tippy.js": "6.2.7", "ts-graphviz": "^2.1.6", "type-coverage": "2.15.1", - "typescript": "5.9.2", + "typescript": "6.0.3", "ua-parser-js": "0.7.40", "uid-number": "0.0.6", "uniqid": "5.3.0", @@ -834,7 +835,7 @@ "buffer": "6.0.3", "process": "0.11.10", "react-router-dom": "6.3.0", - "typescript": "5.9.2", + "typescript": "6.0.3", // @parcel/css, lightningcss, @swc/css are used by css-minimizer-webpack-plugin // see this issue https://github.com/webpack-contrib/css-minimizer-webpack-plugin/issues/244 "@parcel/css": "^1.8.3",