Skip to content

Commit

Permalink
🤖 Pick PR #38101 (Skip comparing optional property fl...) into releas…
Browse files Browse the repository at this point in the history
…e-3.9 (#38199)

* Cherry-pick PR #38101 into release-3.9

Component commits:
f0aeef1 Skip comparing optional property flag when comparing against discriminant properties

* Update LKG

Co-authored-by: Wesley Wigham <[email protected]>
Co-authored-by: typescript-bot <[email protected]>
  • Loading branch information
3 people authored Apr 26, 2020
1 parent cefa5f4 commit f2c9398
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 28 deletions.
8 changes: 4 additions & 4 deletions lib/tsc.js
Original file line number Diff line number Diff line change
Expand Up @@ -41603,7 +41603,7 @@ var ts;
return "continue-outer";
if (sourceProperty === targetProperty)
return "continue";
var related = propertyRelatedTo(source, target, sourceProperty, targetProperty, function (_) { return combination[i]; }, false, 0);
var related = propertyRelatedTo(source, target, sourceProperty, targetProperty, function (_) { return combination[i]; }, false, 0, strictNullChecks || relation === comparableRelation);
if (!related) {
return "continue-outer";
}
Expand Down Expand Up @@ -41702,7 +41702,7 @@ var ts;
return isRelatedTo(source, addOptionality(getTypeOfSymbol(targetProp), targetIsOptional), reportErrors, undefined, intersectionState);
}
}
function propertyRelatedTo(source, target, sourceProp, targetProp, getTypeOfSourceProperty, reportErrors, intersectionState) {
function propertyRelatedTo(source, target, sourceProp, targetProp, getTypeOfSourceProperty, reportErrors, intersectionState, skipOptional) {
var sourcePropFlags = ts.getDeclarationModifierFlagsFromSymbol(sourceProp);
var targetPropFlags = ts.getDeclarationModifierFlagsFromSymbol(targetProp);
if (sourcePropFlags & 8 || targetPropFlags & 8) {
Expand Down Expand Up @@ -41739,7 +41739,7 @@ var ts;
}
return 0;
}
if (relation !== comparableRelation && sourceProp.flags & 16777216 && !(targetProp.flags & 16777216)) {
if (!skipOptional && sourceProp.flags & 16777216 && !(targetProp.flags & 16777216)) {
if (reportErrors) {
reportError(ts.Diagnostics.Property_0_is_optional_in_type_1_but_required_in_type_2, symbolToString(targetProp), typeToString(source), typeToString(target));
}
Expand Down Expand Up @@ -41853,7 +41853,7 @@ var ts;
if (!(targetProp.flags & 4194304) && (!numericNamesOnly || isNumericLiteralName(name) || name === "length")) {
var sourceProp = getPropertyOfType(source, name);
if (sourceProp && sourceProp !== targetProp) {
var related = propertyRelatedTo(source, target, sourceProp, targetProp, getTypeOfSymbol, reportErrors, intersectionState);
var related = propertyRelatedTo(source, target, sourceProp, targetProp, getTypeOfSymbol, reportErrors, intersectionState, relation === comparableRelation);
if (!related) {
return 0;
}
Expand Down
8 changes: 4 additions & 4 deletions lib/tsserver.js
Original file line number Diff line number Diff line change
Expand Up @@ -49915,7 +49915,7 @@ var ts;
if (sourceProperty === targetProperty)
return "continue";
// We compare the source property to the target in the context of a single discriminant type.
var related = propertyRelatedTo(source, target, sourceProperty, targetProperty, function (_) { return combination[i]; }, /*reportErrors*/ false, 0 /* None */);
var related = propertyRelatedTo(source, target, sourceProperty, targetProperty, function (_) { return combination[i]; }, /*reportErrors*/ false, 0 /* None */, /*skipOptional*/ strictNullChecks || relation === comparableRelation);
// If the target property could not be found, or if the properties were not related,
// then this constituent is not a match.
if (!related) {
Expand Down Expand Up @@ -50023,7 +50023,7 @@ var ts;
return isRelatedTo(source, addOptionality(getTypeOfSymbol(targetProp), targetIsOptional), reportErrors, /*headMessage*/ undefined, intersectionState);
}
}
function propertyRelatedTo(source, target, sourceProp, targetProp, getTypeOfSourceProperty, reportErrors, intersectionState) {
function propertyRelatedTo(source, target, sourceProp, targetProp, getTypeOfSourceProperty, reportErrors, intersectionState, skipOptional) {
var sourcePropFlags = ts.getDeclarationModifierFlagsFromSymbol(sourceProp);
var targetPropFlags = ts.getDeclarationModifierFlagsFromSymbol(targetProp);
if (sourcePropFlags & 8 /* Private */ || targetPropFlags & 8 /* Private */) {
Expand Down Expand Up @@ -50062,7 +50062,7 @@ var ts;
return 0 /* False */;
}
// When checking for comparability, be more lenient with optional properties.
if (relation !== comparableRelation && sourceProp.flags & 16777216 /* Optional */ && !(targetProp.flags & 16777216 /* Optional */)) {
if (!skipOptional && sourceProp.flags & 16777216 /* Optional */ && !(targetProp.flags & 16777216 /* Optional */)) {
// TypeScript 1.0 spec (April 2014): 3.8.3
// S is a subtype of a type T, and T is a supertype of S if ...
// S' and T are object types and, for each member M in T..
Expand Down Expand Up @@ -50187,7 +50187,7 @@ var ts;
if (!(targetProp.flags & 4194304 /* Prototype */) && (!numericNamesOnly || isNumericLiteralName(name) || name === "length")) {
var sourceProp = getPropertyOfType(source, name);
if (sourceProp && sourceProp !== targetProp) {
var related = propertyRelatedTo(source, target, sourceProp, targetProp, getTypeOfSymbol, reportErrors, intersectionState);
var related = propertyRelatedTo(source, target, sourceProp, targetProp, getTypeOfSymbol, reportErrors, intersectionState, relation === comparableRelation);
if (!related) {
return 0 /* False */;
}
Expand Down
8 changes: 4 additions & 4 deletions lib/tsserverlibrary.js
Original file line number Diff line number Diff line change
Expand Up @@ -50065,7 +50065,7 @@ var ts;
if (sourceProperty === targetProperty)
return "continue";
// We compare the source property to the target in the context of a single discriminant type.
var related = propertyRelatedTo(source, target, sourceProperty, targetProperty, function (_) { return combination[i]; }, /*reportErrors*/ false, 0 /* None */);
var related = propertyRelatedTo(source, target, sourceProperty, targetProperty, function (_) { return combination[i]; }, /*reportErrors*/ false, 0 /* None */, /*skipOptional*/ strictNullChecks || relation === comparableRelation);
// If the target property could not be found, or if the properties were not related,
// then this constituent is not a match.
if (!related) {
Expand Down Expand Up @@ -50173,7 +50173,7 @@ var ts;
return isRelatedTo(source, addOptionality(getTypeOfSymbol(targetProp), targetIsOptional), reportErrors, /*headMessage*/ undefined, intersectionState);
}
}
function propertyRelatedTo(source, target, sourceProp, targetProp, getTypeOfSourceProperty, reportErrors, intersectionState) {
function propertyRelatedTo(source, target, sourceProp, targetProp, getTypeOfSourceProperty, reportErrors, intersectionState, skipOptional) {
var sourcePropFlags = ts.getDeclarationModifierFlagsFromSymbol(sourceProp);
var targetPropFlags = ts.getDeclarationModifierFlagsFromSymbol(targetProp);
if (sourcePropFlags & 8 /* Private */ || targetPropFlags & 8 /* Private */) {
Expand Down Expand Up @@ -50212,7 +50212,7 @@ var ts;
return 0 /* False */;
}
// When checking for comparability, be more lenient with optional properties.
if (relation !== comparableRelation && sourceProp.flags & 16777216 /* Optional */ && !(targetProp.flags & 16777216 /* Optional */)) {
if (!skipOptional && sourceProp.flags & 16777216 /* Optional */ && !(targetProp.flags & 16777216 /* Optional */)) {
// TypeScript 1.0 spec (April 2014): 3.8.3
// S is a subtype of a type T, and T is a supertype of S if ...
// S' and T are object types and, for each member M in T..
Expand Down Expand Up @@ -50337,7 +50337,7 @@ var ts;
if (!(targetProp.flags & 4194304 /* Prototype */) && (!numericNamesOnly || isNumericLiteralName(name) || name === "length")) {
var sourceProp = getPropertyOfType(source, name);
if (sourceProp && sourceProp !== targetProp) {
var related = propertyRelatedTo(source, target, sourceProp, targetProp, getTypeOfSymbol, reportErrors, intersectionState);
var related = propertyRelatedTo(source, target, sourceProp, targetProp, getTypeOfSymbol, reportErrors, intersectionState, relation === comparableRelation);
if (!related) {
return 0 /* False */;
}
Expand Down
8 changes: 4 additions & 4 deletions lib/typescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -50065,7 +50065,7 @@ var ts;
if (sourceProperty === targetProperty)
return "continue";
// We compare the source property to the target in the context of a single discriminant type.
var related = propertyRelatedTo(source, target, sourceProperty, targetProperty, function (_) { return combination[i]; }, /*reportErrors*/ false, 0 /* None */);
var related = propertyRelatedTo(source, target, sourceProperty, targetProperty, function (_) { return combination[i]; }, /*reportErrors*/ false, 0 /* None */, /*skipOptional*/ strictNullChecks || relation === comparableRelation);
// If the target property could not be found, or if the properties were not related,
// then this constituent is not a match.
if (!related) {
Expand Down Expand Up @@ -50173,7 +50173,7 @@ var ts;
return isRelatedTo(source, addOptionality(getTypeOfSymbol(targetProp), targetIsOptional), reportErrors, /*headMessage*/ undefined, intersectionState);
}
}
function propertyRelatedTo(source, target, sourceProp, targetProp, getTypeOfSourceProperty, reportErrors, intersectionState) {
function propertyRelatedTo(source, target, sourceProp, targetProp, getTypeOfSourceProperty, reportErrors, intersectionState, skipOptional) {
var sourcePropFlags = ts.getDeclarationModifierFlagsFromSymbol(sourceProp);
var targetPropFlags = ts.getDeclarationModifierFlagsFromSymbol(targetProp);
if (sourcePropFlags & 8 /* Private */ || targetPropFlags & 8 /* Private */) {
Expand Down Expand Up @@ -50212,7 +50212,7 @@ var ts;
return 0 /* False */;
}
// When checking for comparability, be more lenient with optional properties.
if (relation !== comparableRelation && sourceProp.flags & 16777216 /* Optional */ && !(targetProp.flags & 16777216 /* Optional */)) {
if (!skipOptional && sourceProp.flags & 16777216 /* Optional */ && !(targetProp.flags & 16777216 /* Optional */)) {
// TypeScript 1.0 spec (April 2014): 3.8.3
// S is a subtype of a type T, and T is a supertype of S if ...
// S' and T are object types and, for each member M in T..
Expand Down Expand Up @@ -50337,7 +50337,7 @@ var ts;
if (!(targetProp.flags & 4194304 /* Prototype */) && (!numericNamesOnly || isNumericLiteralName(name) || name === "length")) {
var sourceProp = getPropertyOfType(source, name);
if (sourceProp && sourceProp !== targetProp) {
var related = propertyRelatedTo(source, target, sourceProp, targetProp, getTypeOfSymbol, reportErrors, intersectionState);
var related = propertyRelatedTo(source, target, sourceProp, targetProp, getTypeOfSymbol, reportErrors, intersectionState, relation === comparableRelation);
if (!related) {
return 0 /* False */;
}
Expand Down
8 changes: 4 additions & 4 deletions lib/typescriptServices.js
Original file line number Diff line number Diff line change
Expand Up @@ -50065,7 +50065,7 @@ var ts;
if (sourceProperty === targetProperty)
return "continue";
// We compare the source property to the target in the context of a single discriminant type.
var related = propertyRelatedTo(source, target, sourceProperty, targetProperty, function (_) { return combination[i]; }, /*reportErrors*/ false, 0 /* None */);
var related = propertyRelatedTo(source, target, sourceProperty, targetProperty, function (_) { return combination[i]; }, /*reportErrors*/ false, 0 /* None */, /*skipOptional*/ strictNullChecks || relation === comparableRelation);
// If the target property could not be found, or if the properties were not related,
// then this constituent is not a match.
if (!related) {
Expand Down Expand Up @@ -50173,7 +50173,7 @@ var ts;
return isRelatedTo(source, addOptionality(getTypeOfSymbol(targetProp), targetIsOptional), reportErrors, /*headMessage*/ undefined, intersectionState);
}
}
function propertyRelatedTo(source, target, sourceProp, targetProp, getTypeOfSourceProperty, reportErrors, intersectionState) {
function propertyRelatedTo(source, target, sourceProp, targetProp, getTypeOfSourceProperty, reportErrors, intersectionState, skipOptional) {
var sourcePropFlags = ts.getDeclarationModifierFlagsFromSymbol(sourceProp);
var targetPropFlags = ts.getDeclarationModifierFlagsFromSymbol(targetProp);
if (sourcePropFlags & 8 /* Private */ || targetPropFlags & 8 /* Private */) {
Expand Down Expand Up @@ -50212,7 +50212,7 @@ var ts;
return 0 /* False */;
}
// When checking for comparability, be more lenient with optional properties.
if (relation !== comparableRelation && sourceProp.flags & 16777216 /* Optional */ && !(targetProp.flags & 16777216 /* Optional */)) {
if (!skipOptional && sourceProp.flags & 16777216 /* Optional */ && !(targetProp.flags & 16777216 /* Optional */)) {
// TypeScript 1.0 spec (April 2014): 3.8.3
// S is a subtype of a type T, and T is a supertype of S if ...
// S' and T are object types and, for each member M in T..
Expand Down Expand Up @@ -50337,7 +50337,7 @@ var ts;
if (!(targetProp.flags & 4194304 /* Prototype */) && (!numericNamesOnly || isNumericLiteralName(name) || name === "length")) {
var sourceProp = getPropertyOfType(source, name);
if (sourceProp && sourceProp !== targetProp) {
var related = propertyRelatedTo(source, target, sourceProp, targetProp, getTypeOfSymbol, reportErrors, intersectionState);
var related = propertyRelatedTo(source, target, sourceProp, targetProp, getTypeOfSymbol, reportErrors, intersectionState, relation === comparableRelation);
if (!related) {
return 0 /* False */;
}
Expand Down
8 changes: 4 additions & 4 deletions lib/typingsInstaller.js
Original file line number Diff line number Diff line change
Expand Up @@ -49904,7 +49904,7 @@ var ts;
if (sourceProperty === targetProperty)
return "continue";
// We compare the source property to the target in the context of a single discriminant type.
var related = propertyRelatedTo(source, target, sourceProperty, targetProperty, function (_) { return combination[i]; }, /*reportErrors*/ false, 0 /* None */);
var related = propertyRelatedTo(source, target, sourceProperty, targetProperty, function (_) { return combination[i]; }, /*reportErrors*/ false, 0 /* None */, /*skipOptional*/ strictNullChecks || relation === comparableRelation);
// If the target property could not be found, or if the properties were not related,
// then this constituent is not a match.
if (!related) {
Expand Down Expand Up @@ -50012,7 +50012,7 @@ var ts;
return isRelatedTo(source, addOptionality(getTypeOfSymbol(targetProp), targetIsOptional), reportErrors, /*headMessage*/ undefined, intersectionState);
}
}
function propertyRelatedTo(source, target, sourceProp, targetProp, getTypeOfSourceProperty, reportErrors, intersectionState) {
function propertyRelatedTo(source, target, sourceProp, targetProp, getTypeOfSourceProperty, reportErrors, intersectionState, skipOptional) {
var sourcePropFlags = ts.getDeclarationModifierFlagsFromSymbol(sourceProp);
var targetPropFlags = ts.getDeclarationModifierFlagsFromSymbol(targetProp);
if (sourcePropFlags & 8 /* Private */ || targetPropFlags & 8 /* Private */) {
Expand Down Expand Up @@ -50051,7 +50051,7 @@ var ts;
return 0 /* False */;
}
// When checking for comparability, be more lenient with optional properties.
if (relation !== comparableRelation && sourceProp.flags & 16777216 /* Optional */ && !(targetProp.flags & 16777216 /* Optional */)) {
if (!skipOptional && sourceProp.flags & 16777216 /* Optional */ && !(targetProp.flags & 16777216 /* Optional */)) {
// TypeScript 1.0 spec (April 2014): 3.8.3
// S is a subtype of a type T, and T is a supertype of S if ...
// S' and T are object types and, for each member M in T..
Expand Down Expand Up @@ -50176,7 +50176,7 @@ var ts;
if (!(targetProp.flags & 4194304 /* Prototype */) && (!numericNamesOnly || isNumericLiteralName(name) || name === "length")) {
var sourceProp = getPropertyOfType(source, name);
if (sourceProp && sourceProp !== targetProp) {
var related = propertyRelatedTo(source, target, sourceProp, targetProp, getTypeOfSymbol, reportErrors, intersectionState);
var related = propertyRelatedTo(source, target, sourceProp, targetProp, getTypeOfSymbol, reportErrors, intersectionState, relation === comparableRelation);
if (!related) {
return 0 /* False */;
}
Expand Down
Loading

0 comments on commit f2c9398

Please sign in to comment.