Skip to content

Conversation

DanielRosenwasser
Copy link
Member

Especially given that tsc --init initializes with VMS.

@Copilot Copilot AI review requested due to automatic review settings July 23, 2025 17:58
@github-project-automation github-project-automation bot moved this to Not started in PR Backlog Jul 23, 2025
@typescript-bot typescript-bot added For Uncommitted Bug PR for untriaged, rejected, closed or missing bug labels Jul 23, 2025
Copy link

@Copilot 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

This PR improves error messages for the verbatimModuleSyntax TypeScript compiler option to provide more specific and actionable guidance to developers. The change replaces generic "ESM syntax is not allowed" messages with detailed explanations that include specific configuration suggestions.

Key Changes

  • Replaces generic TS1286 error message with a new, more detailed TS1295 error message for verbatimModuleSyntax violations
  • Adds conditional logic to provide different error messages based on file extensions (.cts/.cjs vs other files)
  • Updates error message for module: preserve mode to be more descriptive

Reviewed Changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.

File Description
src/compiler/diagnosticMessages.json Adds new detailed error message (TS1295) and updates existing messages to be more specific
src/compiler/checker.ts Implements logic to conditionally show different error messages based on file type and adds helper function
tests/baselines/reference/*.errors.txt Updates test baselines to reflect the new, more detailed error messages

// Check if the file is .cts or .cjs (CommonJS-specific extensions)
if (fileExtensionIsOneOf(fileName, [Extension.Cts, Extension.Cjs])) {
return Diagnostics.ECMAScript_imports_and_exports_cannot_be_written_in_a_CommonJS_file_under_verbatimModuleSyntax;
} else {
Copy link
Preview

Copilot AI Jul 23, 2025

Choose a reason for hiding this comment

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

The error message for .cts/.cjs files should provide guidance on how to resolve the issue, similar to the detailed message used for other file types. Currently it only states what's wrong without offering solutions.

Suggested change
} else {
if (fileExtensionIsOneOf(fileName, [Extension.Cts, Extension.Cjs])) {
return Diagnostics.ECMAScript_imports_and_exports_cannot_be_written_in_a_CommonJS_file_under_verbatimModuleSyntax_Adjust_the_type_field_in_the_nearest_package_json_to_make_this_file_an_ECMAScript_module_or_adjust_your_verbatimModuleSyntax_module_and_moduleResolution_settings_in_TypeScript;
} else {

Copilot uses AI. Check for mistakes.

@github-project-automation github-project-automation bot moved this from Not started to Needs merge in PR Backlog Jul 23, 2025
@DanielRosenwasser DanielRosenwasser merged commit be86783 into main Jul 23, 2025
31 checks passed
@DanielRosenwasser DanielRosenwasser deleted the esmMessageVerbatimModuleSyntax branch July 23, 2025 22:38
@github-project-automation github-project-automation bot moved this from Needs merge to Done in PR Backlog Jul 23, 2025
@DanielRosenwasser DanielRosenwasser added this to the TypeScript 5.9.1 milestone Jul 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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.

4 participants