diff --git a/tsc/internal/checker/utilities.go b/tsc/internal/checker/utilities.go index d8ef84a30e09d..c73c6a53f48c5 100644 --- a/tsc/internal/checker/utilities.go +++ b/tsc/internal/checker/utilities.go @@ -431,6 +431,18 @@ func CompareTypes(t1, t2 *Type) int { if c := getSortOrderFlags(t1) - getSortOrderFlags(t2); c != 0 { return c } + // Fast path for two unaliased string literal types. + if t1.flags == TypeFlagsStringLiteral && t2.flags == TypeFlagsStringLiteral && t1.alias == nil && t2.alias == nil { + s1 := t1.AsLiteralType().value.(string) + s2 := t2.AsLiteralType().value.(string) + if s1 != s2 { + if s1 < s2 { + return -1 + } + return 1 + } + return int(t1.id) - int(t2.id) + } // Order named types by name and, in the case of aliased types, by alias type arguments. if c := compareTypeNames(t1, t2); c != 0 { return c