Skip to content

Improve TypeScript error messages for long type assignments #61776

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions modify_checker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env python3

# Read the file
with open('src/compiler/checker.ts', 'r', encoding='utf-8') as f:
lines = f.readlines()

# Find the line to replace (should be around line 22489)
target_line = " reportError(message, generalizedSourceType, targetType);\n"
replacement = """ // Check if both types are long and format differently for better readability
if (message === Diagnostics.Type_0_is_not_assignable_to_type_1 &&
generalizedSourceType.length > 30 && targetType.length > 30) {
// Remove quotes from type strings and format with newlines
const sourceTypeUnquoted = generalizedSourceType.replace(/^'|'$/g, "");
const targetTypeUnquoted = targetType.replace(/^'|'$/g, "");
const customMessage = {
...message,
message: `Type: \\n${sourceTypeUnquoted}\\n\\nis not assignable to type:\\n${targetTypeUnquoted}`
};
reportError(customMessage);
} else {
reportError(message, generalizedSourceType, targetType);
}
"""

# Replace the line
for i, line in enumerate(lines):
if line == target_line:
lines[i] = replacement + "\n"
print(f"Replaced line {i+1}")
break
else:
print("Target line not found")

# Write the file back
with open('src/compiler/checker.ts', 'w', encoding='utf-8') as f:
f.writelines(lines)

print("File modified successfully")
Loading
Loading