Skip to content
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