Skip to content

Commit ec49a22

Browse files
committed
Improve TypeScript error messages for long type assignments
1 parent 48f1178 commit ec49a22

3 files changed

Lines changed: 107138 additions & 53543 deletions

File tree

modify_checker.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/env python3
2+
3+
# Read the file
4+
with open('src/compiler/checker.ts', 'r', encoding='utf-8') as f:
5+
lines = f.readlines()
6+
7+
# Find the line to replace (should be around line 22489)
8+
target_line = " reportError(message, generalizedSourceType, targetType);\n"
9+
replacement = """ // Check if both types are long and format differently for better readability
10+
if (message === Diagnostics.Type_0_is_not_assignable_to_type_1 &&
11+
generalizedSourceType.length > 30 && targetType.length > 30) {
12+
// Remove quotes from type strings and format with newlines
13+
const sourceTypeUnquoted = generalizedSourceType.replace(/^'|'$/g, "");
14+
const targetTypeUnquoted = targetType.replace(/^'|'$/g, "");
15+
const customMessage = {
16+
...message,
17+
message: `Type: \\n${sourceTypeUnquoted}\\n\\nis not assignable to type:\\n${targetTypeUnquoted}`
18+
};
19+
reportError(customMessage);
20+
} else {
21+
reportError(message, generalizedSourceType, targetType);
22+
}
23+
"""
24+
25+
# Replace the line
26+
for i, line in enumerate(lines):
27+
if line == target_line:
28+
lines[i] = replacement + "\n"
29+
print(f"Replaced line {i+1}")
30+
break
31+
else:
32+
print("Target line not found")
33+
34+
# Write the file back
35+
with open('src/compiler/checker.ts', 'w', encoding='utf-8') as f:
36+
f.writelines(lines)
37+
38+
print("File modified successfully")

0 commit comments

Comments
 (0)