Skip to content

tsc --init update#61813

Merged
RyanCavanaugh merged 14 commits intomicrosoft:mainfrom
RyanCavanaugh:tsc-init
Jun 6, 2025
Merged

tsc --init update#61813
RyanCavanaugh merged 14 commits intomicrosoft:mainfrom
RyanCavanaugh:tsc-init

Conversation

@RyanCavanaugh
Copy link
Copy Markdown
Member

@RyanCavanaugh RyanCavanaugh commented Jun 4, 2025

Fixes #58420

Sample outputs

tsc --init

{
  // Visit https://aka.ms/tsconfig to read more about this file
  "compilerOptions": {
    // File Layout
    // "rootDir": "./src",
    // "outDir": "./dist",

    // Environment Settings
    // See also https://aka.ms/tsconfig_modules
    "module": "nodenext",
    "target": "esnext",
    "types": [],
    // For nodejs:
    // "lib": ["esnext"],
    // "types": ["node"],
    // and npm install -D @types/node

    // Other Outputs
    "sourceMap": true,
    "declaration": true,
    "declarationMap": true,

    // Stricter Typechecking Options
    "noUncheckedIndexedAccess": true,
    "exactOptionalPropertyTypes": true,

    // Style Options
    // "noImplicitReturns": true,
    // "noImplicitOverride": true,
    // "noUnusedLocals": true,
    // "noUnusedParameters": true,
    // "noFallthroughCasesInSwitch": true,
    // "noPropertyAccessFromIndexSignature": true,

    // Recommended Options
    "strict": true,
    "jsx": "react-jsx",
    "verbatimModuleSyntax": true,
    "isolatedModules": true,
    "noUncheckedSideEffectImports": true,
    "moduleDetection": "force",
    "skipLibCheck": true,
  }
}

tsc --init --noImplicitAny false --target es2022 --lib dom --rootDir src --types mocha --noImplicitReturns

{
  // Visit https://aka.ms/tsconfig to read more about this file
  "compilerOptions": {
    // File Layout
    "rootDir": "src",
    // "outDir": "./dist",

    // Environment Settings
    // See also https://aka.ms/tsconfig_modules
    "module": "nodenext",
    "target": "es2022",
    "types": ["mocha"],
    "lib": ["dom"],
    // For nodejs:
    // "lib": ["esnext"],
    // "types": ["node"],
    // and npm install -D @types/node

    // Other Outputs
    "sourceMap": true,
    "declaration": true,
    "declarationMap": true,

    // Stricter Typechecking Options
    "noUncheckedIndexedAccess": true,
    "exactOptionalPropertyTypes": true,

    // Style Options
    "noImplicitReturns": true,
    // "noImplicitOverride": true,
    // "noUnusedLocals": true,
    // "noUnusedParameters": true,
    // "noFallthroughCasesInSwitch": true,
    // "noPropertyAccessFromIndexSignature": true,

    // Recommended Options
    "strict": true,
    "jsx": "react-jsx",
    "verbatimModuleSyntax": true,
    "isolatedModules": true,
    "noUncheckedSideEffectImports": true,
    "moduleDetection": "force",
    "skipLibCheck": true,

    "noImplicitAny": false,
  }
}

Copilot AI review requested due to automatic review settings June 4, 2025 16:38
@github-project-automation github-project-automation Bot moved this to Not started in PR Backlog Jun 4, 2025
@typescript-bot typescript-bot added Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug labels Jun 4, 2025

This comment was marked as outdated.

@RyanCavanaugh RyanCavanaugh requested a review from Copilot June 4, 2025 17:05
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Updates the --init logic to streamline how tsconfig.json is generated and simplify related tests and CLI handling. Key changes include:

  • Refactored generateTSConfig signature and implementation to remove file list parameter and output clean, sectioned JSON.
  • Updated writeConfigFile and test invocations to match new generateTSConfig signature.
  • Added diagnostic message entries for each new section header.

Reviewed Changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 1 comment.

File Description
src/compiler/commandLineParser.ts Replaced old getCompilerOptionsDiffValue and rewritten generateTSConfig with new API.
src/compiler/executeCommandLine.ts Updated writeConfigFile to call new generateTSConfig signature and cleaned output.
src/testRunner/unittests/config/initializeTSConfig.ts Adjusted test helper to use new generateTSConfig(options, newLine) call.
src/compiler/diagnosticMessages.json Inserted new diagnostic entries for section headers used in generated JSON.
Comments suppressed due to low confidence (1)

src/compiler/commandLineParser.ts:2930

  • Consider appending a trailing newline to the generated config for consistency with existing baselines and editor tooling. For example: return result.join(newLine) + newLine;
    return result.join(newLine);

Comment thread src/compiler/diagnosticMessages.json
Comment thread src/compiler/diagnosticMessages.json Outdated
export function generateTSConfig(options: CompilerOptions, fileNames: readonly string[], newLine: string): string {
const compilerOptionsMap = getSerializedCompilerOption(options);
return writeConfigurations();
export function generateTSConfig(options: CompilerOptions, newLine: string): string {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was like "oh no, hope nobody calls this", but no, it's all callers from 5+ years ago (https://github.com/search?q=%2Fts%28+as+%5B%5E%28%5D%2B%5C%29%29%3F%5C.generateTSConfig%5C%28%2F+-path%3Atestrunner&type=code)

@github-project-automation github-project-automation Bot moved this from Not started to Needs merge in PR Backlog Jun 4, 2025
// Other Outputs
"sourceMap": true,
"declaration": true,
"declarationMap": true,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably already discussed when i wasnt here, but declarationMap seems like overkill ? and additional cost?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest we just comment it out.

// See also https://aka.ms/tsconfig/module
"module": "nodenext",
"target": "esnext",
"types": [],
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a silly idea, but should we note the effect that this has?

Comment on lines -113 to -117
"files": [
"file0.st",
"file1.ts",
"file2.ts"
]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this intentional? I assume so?

@jakebailey
Copy link
Copy Markdown
Member

Outside what I commented, everything is looking great.

Copy link
Copy Markdown
Member

@jakebailey jakebailey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In any case, giving this another +1 since it's what was spec'd out, but if we do want to drop declarationMap that's fine too.

@RyanCavanaugh RyanCavanaugh merged commit cd34199 into microsoft:main Jun 6, 2025
32 checks passed
@github-project-automation github-project-automation Bot moved this from Needs merge to Done in PR Backlog Jun 6, 2025
@RyanCavanaugh RyanCavanaugh deleted the tsc-init branch June 6, 2025 19:03
@robpalme
Copy link
Copy Markdown

robpalme commented Jun 7, 2025

There's a typo that caught my eye in the PR description. The code itself is fine.

 "target": "nodenext",

It should say "esnext"

@jakebailey
Copy link
Copy Markdown
Member

Edited it. And it should also have said module=nodenext

haoqunjiang added a commit to vuejs/tsconfig that referenced this pull request Jul 17, 2025
haoqunjiang added a commit to vuejs/tsconfig that referenced this pull request Aug 15, 2025
…pes` (#36)

See https://www.semver-ts.org/formal-spec/5-compiler-considerations.html#strictness for the arguments for turning these options on.

Both are now turned on by default in the `tsc --init` template of TS 5.9 microsoft/TypeScript#61813
@microsoft microsoft locked as resolved and limited conversation to collaborators Apr 17, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

tsc --init update 2024

7 participants