mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Port "Improve type discrimination algorithm" from tsgo (#61828)
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user