Port "Improve type discrimination algorithm" from tsgo (#61828)

This commit is contained in:
Jake Bailey
2025-06-09 16:20:15 -07:00
committed by GitHub
parent 0dfd0c2143
commit 12e09f44f6
8 changed files with 239 additions and 29 deletions
+7 -5
View File
@@ -24802,11 +24802,13 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
for (let i = 0; i < types.length; i++) {
if (include[i]) {
const targetType = getTypeOfPropertyOrIndexSignatureOfType(types[i], propertyName);
if (targetType && someType(getDiscriminatingType(), t => !!related(t, targetType))) {
matched = true;
}
else {
include[i] = Ternary.Maybe;
if (targetType) {
if (someType(getDiscriminatingType(), t => !!related(t, targetType))) {
matched = true;
}
else {
include[i] = Ternary.Maybe;
}
}
}
}
+1 -1
View File
@@ -370,7 +370,7 @@ function createImportAdderWorker(sourceFile: SourceFile | FutureSourceFile, prog
);
let fix: FixAddNewImport | ImportFixWithModuleSpecifier;
if (existingFix && importKind !== ImportKind.Namespace) {
if (existingFix && importKind !== ImportKind.Namespace && existingFix.kind !== ImportFixKind.UseNamespace && existingFix.kind !== ImportFixKind.JsdocTypeImport) {
fix = {
...existingFix,
addAsTypeOnly,