Fix instanceof use with Symbol.hasInstance in conjunction with union/intersection (#57602)

This commit is contained in:
Ron Buckton
2024-03-01 19:09:28 -05:00
committed by GitHub
parent f4eeea052e
commit ea0d228f83
5 changed files with 158 additions and 7 deletions
+7 -5
View File
@@ -37974,11 +37974,13 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
*/
function getSymbolHasInstanceMethodOfObjectType(type: Type) {
const hasInstancePropertyName = getPropertyNameForKnownSymbolName("hasInstance");
const hasInstanceProperty = getPropertyOfObjectType(type, hasInstancePropertyName);
if (hasInstanceProperty) {
const hasInstancePropertyType = getTypeOfSymbol(hasInstanceProperty);
if (hasInstancePropertyType && getSignaturesOfType(hasInstancePropertyType, SignatureKind.Call).length !== 0) {
return hasInstancePropertyType;
if (allTypesAssignableToKind(type, TypeFlags.NonPrimitive)) {
const hasInstanceProperty = getPropertyOfType(type, hasInstancePropertyName);
if (hasInstanceProperty) {
const hasInstancePropertyType = getTypeOfSymbol(hasInstanceProperty);
if (hasInstancePropertyType && getSignaturesOfType(hasInstancePropertyType, SignatureKind.Call).length !== 0) {
return hasInstancePropertyType;
}
}
}
}