Skip to content

Error handling test #62219

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

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
Draft
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
3 changes: 3 additions & 0 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40789,6 +40789,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
if (checkForDisallowedESSymbolOperand(operator)) {
leftType = getBaseTypeOfLiteralTypeForComparison(checkNonNullType(leftType, left));
rightType = getBaseTypeOfLiteralTypeForComparison(checkNonNullType(rightType, right));
if (leftType.flags === TypeFlags.String && rightType.flags === TypeFlags.String) {
error(errorNode, Diagnostics.Cannot_compare_strings);
}
reportOperatorErrorUnless((left, right) => {
if (isTypeAny(left) || isTypeAny(right)) {
return true;
Expand Down
4 changes: 4 additions & 0 deletions src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -8519,5 +8519,9 @@
"'{0}' is not a valid meta-property for keyword 'import'. Did you mean 'meta' or 'defer'?": {
"category": "Error",
"code": 18061
},
"Cannot compare strings": {
"category": "Error",
"code": 18062
}
}
6 changes: 6 additions & 0 deletions tests/baselines/reference/stringComp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//// [tests/cases/compiler/stringComp.ts] ////

//// [stringComp.ts]


//// [stringComp.js]
4 changes: 4 additions & 0 deletions tests/baselines/reference/stringComp.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
//// [tests/cases/compiler/stringComp.ts] ////

=== stringComp.ts ===

4 changes: 4 additions & 0 deletions tests/baselines/reference/stringComp.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
//// [tests/cases/compiler/stringComp.ts] ////

=== stringComp.ts ===

3 changes: 3 additions & 0 deletions tests/cases/compiler/stringComp.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
if ("bar" <= "foo") {
console.log("Really?")
}
Loading