mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-13 22:00:59 -05:00
Implement fix for this type comparison false positive
Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com>
This commit is contained in:
@@ -22143,11 +22143,26 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
|
||||
(source as NumberLiteralType).value === (target as NumberLiteralType).value
|
||||
) return true;
|
||||
if (s & TypeFlags.BigIntLike && t & TypeFlags.BigInt) return true;
|
||||
if (s & TypeFlags.BooleanLike && t & TypeFlags.Boolean) return true;
|
||||
if (s & TypeFlags.ESSymbolLike && t & TypeFlags.ESSymbol) return true;
|
||||
if (
|
||||
s & TypeFlags.Enum && t & TypeFlags.Enum && source.symbol.escapedName === target.symbol.escapedName &&
|
||||
isEnumTypeRelatedTo(source.symbol, target.symbol, errorReporter)
|
||||
if (s & TypeFlags.BooleanLike && t & TypeFlags.Boolean) return true;
|
||||
if (s & TypeFlags.ESSymbolLike && t & TypeFlags.ESSymbol) return true;
|
||||
// For comparable relation, revert `this` type parameters back to their constrained class type
|
||||
if (relation === comparableRelation) {
|
||||
if (s & TypeFlags.TypeParameter && (source as TypeParameter).isThisType) {
|
||||
const constraint = getConstraintOfTypeParameter(source as TypeParameter);
|
||||
if (constraint && isTypeRelatedTo(constraint, target, relation)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (t & TypeFlags.TypeParameter && (target as TypeParameter).isThisType) {
|
||||
const constraint = getConstraintOfTypeParameter(target as TypeParameter);
|
||||
if (constraint && isTypeRelatedTo(source, constraint, relation)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (
|
||||
s & TypeFlags.Enum && t & TypeFlags.Enum && source.symbol.escapedName === target.symbol.escapedName &&
|
||||
isEnumTypeRelatedTo(source.symbol, target.symbol, errorReporter)
|
||||
) return true;
|
||||
if (s & TypeFlags.EnumLiteral && t & TypeFlags.EnumLiteral) {
|
||||
if (s & TypeFlags.Union && t & TypeFlags.Union && isEnumTypeRelatedTo(source.symbol, target.symbol, errorReporter)) return true;
|
||||
|
||||
Reference in New Issue
Block a user