typescript 4.6.1-rc → 4.6.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -89,7 +89,7 @@ var ts;
89
89
  // The following is baselined as a literal template type without intervention
90
90
  /** The version of the TypeScript compiler release */
91
91
  // eslint-disable-next-line @typescript-eslint/no-inferrable-types
92
- ts.version = "".concat(ts.versionMajorMinor, ".1-rc");
92
+ ts.version = "4.6.3";
93
93
  /* @internal */
94
94
  var Comparison;
95
95
  (function (Comparison) {
@@ -4829,6 +4829,8 @@ var ts;
4829
4829
  TypeFlags[TypeFlags["ESSymbolLike"] = 12288] = "ESSymbolLike";
4830
4830
  TypeFlags[TypeFlags["VoidLike"] = 49152] = "VoidLike";
4831
4831
  /* @internal */
4832
+ TypeFlags[TypeFlags["DefinitelyNonNullable"] = 470302716] = "DefinitelyNonNullable";
4833
+ /* @internal */
4832
4834
  TypeFlags[TypeFlags["DisjointDomains"] = 469892092] = "DisjointDomains";
4833
4835
  TypeFlags[TypeFlags["UnionOrIntersection"] = 3145728] = "UnionOrIntersection";
4834
4836
  TypeFlags[TypeFlags["StructuredType"] = 3670016] = "StructuredType";
@@ -8070,6 +8072,8 @@ var ts;
8070
8072
  Property_0_cannot_have_an_initializer_because_it_is_marked_abstract: diag(1267, ts.DiagnosticCategory.Error, "Property_0_cannot_have_an_initializer_because_it_is_marked_abstract_1267", "Property '{0}' cannot have an initializer because it is marked abstract."),
8071
8073
  An_index_signature_parameter_type_must_be_string_number_symbol_or_a_template_literal_type: diag(1268, ts.DiagnosticCategory.Error, "An_index_signature_parameter_type_must_be_string_number_symbol_or_a_template_literal_type_1268", "An index signature parameter type must be 'string', 'number', 'symbol', or a template literal type."),
8072
8074
  Cannot_use_export_import_on_a_type_or_type_only_namespace_when_the_isolatedModules_flag_is_provided: diag(1269, ts.DiagnosticCategory.Error, "Cannot_use_export_import_on_a_type_or_type_only_namespace_when_the_isolatedModules_flag_is_provided_1269", "Cannot use 'export import' on a type or type-only namespace when the '--isolatedModules' flag is provided."),
8075
+ Decorator_function_return_type_0_is_not_assignable_to_type_1: diag(1270, ts.DiagnosticCategory.Error, "Decorator_function_return_type_0_is_not_assignable_to_type_1_1270", "Decorator function return type '{0}' is not assignable to type '{1}'."),
8076
+ Decorator_function_return_type_is_0_but_is_expected_to_be_void_or_any: diag(1271, ts.DiagnosticCategory.Error, "Decorator_function_return_type_is_0_but_is_expected_to_be_void_or_any_1271", "Decorator function return type is '{0}' but is expected to be 'void' or 'any'."),
8073
8077
  with_statements_are_not_allowed_in_an_async_function_block: diag(1300, ts.DiagnosticCategory.Error, "with_statements_are_not_allowed_in_an_async_function_block_1300", "'with' statements are not allowed in an async function block."),
8074
8078
  await_expressions_are_only_allowed_within_async_functions_and_at_the_top_levels_of_modules: diag(1308, ts.DiagnosticCategory.Error, "await_expressions_are_only_allowed_within_async_functions_and_at_the_top_levels_of_modules_1308", "'await' expressions are only allowed within async functions and at the top levels of modules."),
8075
8079
  Did_you_mean_to_use_a_Colon_An_can_only_follow_a_property_name_when_the_containing_object_literal_is_part_of_a_destructuring_pattern: diag(1312, ts.DiagnosticCategory.Error, "Did_you_mean_to_use_a_Colon_An_can_only_follow_a_property_name_when_the_containing_object_literal_is_1312", "Did you mean to use a ':'? An '=' can only follow a property name when the containing object literal is part of a destructuring pattern."),
@@ -31339,18 +31343,8 @@ var ts;
31339
31343
  if (tryParseSemicolon()) {
31340
31344
  return;
31341
31345
  }
31342
- // If an initializer was parsed but there is still an error in finding the next semicolon,
31343
- // we generally know there was an error already reported in the initializer...
31344
- // class Example { a = new Map([), ) }
31345
- // ~
31346
31346
  if (initializer) {
31347
- // ...unless we've found the start of a block after a property declaration, in which
31348
- // case we can know that regardless of the initializer we should complain on the block.
31349
- // class Example { a = 0 {} }
31350
- // ~
31351
- if (token() === 18 /* OpenBraceToken */) {
31352
- parseErrorAtCurrentToken(ts.Diagnostics._0_expected, ts.tokenToString(26 /* SemicolonToken */));
31353
- }
31347
+ parseErrorAtCurrentToken(ts.Diagnostics._0_expected, ts.tokenToString(26 /* SemicolonToken */));
31354
31348
  return;
31355
31349
  }
31356
31350
  parseErrorForMissingSemicolonAfter(name);
@@ -46930,8 +46924,7 @@ var ts;
46930
46924
  IntersectionState[IntersectionState["Source"] = 1] = "Source";
46931
46925
  IntersectionState[IntersectionState["Target"] = 2] = "Target";
46932
46926
  IntersectionState[IntersectionState["PropertyCheck"] = 4] = "PropertyCheck";
46933
- IntersectionState[IntersectionState["UnionIntersectionCheck"] = 8] = "UnionIntersectionCheck";
46934
- IntersectionState[IntersectionState["InPropertyCheck"] = 16] = "InPropertyCheck";
46927
+ IntersectionState[IntersectionState["InPropertyCheck"] = 8] = "InPropertyCheck";
46935
46928
  })(IntersectionState || (IntersectionState = {}));
46936
46929
  var RecursionFlags;
46937
46930
  (function (RecursionFlags) {
@@ -63217,11 +63210,11 @@ var ts;
63217
63210
  var overflow = false;
63218
63211
  var overrideNextErrorInfo = 0; // How many `reportRelationError` calls should be skipped in the elaboration pyramid
63219
63212
  var lastSkippedInfo;
63220
- var incompatibleStack = [];
63213
+ var incompatibleStack;
63221
63214
  var inPropertyCheck = false;
63222
63215
  ts.Debug.assert(relation !== identityRelation || !errorNode, "no error reporting in identity checking");
63223
63216
  var result = isRelatedTo(source, target, 3 /* Both */, /*reportErrors*/ !!errorNode, headMessage);
63224
- if (incompatibleStack.length) {
63217
+ if (incompatibleStack) {
63225
63218
  reportIncompatibleStack();
63226
63219
  }
63227
63220
  if (overflow) {
@@ -63278,19 +63271,19 @@ var ts;
63278
63271
  return {
63279
63272
  errorInfo: errorInfo,
63280
63273
  lastSkippedInfo: lastSkippedInfo,
63281
- incompatibleStack: incompatibleStack.slice(),
63274
+ incompatibleStack: incompatibleStack === null || incompatibleStack === void 0 ? void 0 : incompatibleStack.slice(),
63282
63275
  overrideNextErrorInfo: overrideNextErrorInfo,
63283
- relatedInfo: !relatedInfo ? undefined : relatedInfo.slice()
63276
+ relatedInfo: relatedInfo === null || relatedInfo === void 0 ? void 0 : relatedInfo.slice(),
63284
63277
  };
63285
63278
  }
63286
63279
  function reportIncompatibleError(message, arg0, arg1, arg2, arg3) {
63287
63280
  overrideNextErrorInfo++; // Suppress the next relation error
63288
63281
  lastSkippedInfo = undefined; // Reset skipped info cache
63289
- incompatibleStack.push([message, arg0, arg1, arg2, arg3]);
63282
+ (incompatibleStack || (incompatibleStack = [])).push([message, arg0, arg1, arg2, arg3]);
63290
63283
  }
63291
63284
  function reportIncompatibleStack() {
63292
- var stack = incompatibleStack;
63293
- incompatibleStack = [];
63285
+ var stack = incompatibleStack || [];
63286
+ incompatibleStack = undefined;
63294
63287
  var info = lastSkippedInfo;
63295
63288
  lastSkippedInfo = undefined;
63296
63289
  if (stack.length === 1) {
@@ -63396,7 +63389,7 @@ var ts;
63396
63389
  }
63397
63390
  function reportError(message, arg0, arg1, arg2, arg3) {
63398
63391
  ts.Debug.assert(!!errorNode);
63399
- if (incompatibleStack.length)
63392
+ if (incompatibleStack)
63400
63393
  reportIncompatibleStack();
63401
63394
  if (message.elidedInCompatabilityPyramid)
63402
63395
  return;
@@ -63412,7 +63405,7 @@ var ts;
63412
63405
  }
63413
63406
  }
63414
63407
  function reportRelationError(message, source, target) {
63415
- if (incompatibleStack.length)
63408
+ if (incompatibleStack)
63416
63409
  reportIncompatibleStack();
63417
63410
  var _a = getTypeNamesForErrorDisplay(source, target), sourceType = _a[0], targetType = _a[1];
63418
63411
  var generalizedSource = source;
@@ -63524,7 +63517,9 @@ var ts;
63524
63517
  if (isSimpleTypeRelatedTo(originalSource, originalTarget, relation, reportErrors ? reportError : undefined)) {
63525
63518
  return -1 /* True */;
63526
63519
  }
63527
- reportErrorResults(originalSource, originalTarget, 0 /* False */, !!(ts.getObjectFlags(originalSource) & 2048 /* JsxAttributes */));
63520
+ if (reportErrors) {
63521
+ reportErrorResults(originalSource, originalTarget, originalSource, originalTarget, headMessage);
63522
+ }
63528
63523
  return 0 /* False */;
63529
63524
  }
63530
63525
  // Normalize the source and target types: Turn fresh literal types into regular literal types,
@@ -63536,7 +63531,12 @@ var ts;
63536
63531
  if (source === target)
63537
63532
  return -1 /* True */;
63538
63533
  if (relation === identityRelation) {
63539
- return isIdenticalTo(source, target, recursionFlags);
63534
+ if (source.flags !== target.flags)
63535
+ return 0 /* False */;
63536
+ if (source.flags & 67358815 /* Singleton */)
63537
+ return -1 /* True */;
63538
+ traceUnionsOrIntersectionsTooLarge(source, target);
63539
+ return recursiveTypeRelatedTo(source, target, /*reportErrors*/ false, 0 /* None */, recursionFlags);
63540
63540
  }
63541
63541
  // We fastpath comparing a type parameter to exactly its constraint, as this is _super_ common,
63542
63542
  // and otherwise, for type parameters in large unions, causes us to need to compare the union to itself,
@@ -63546,163 +63546,130 @@ var ts;
63546
63546
  if (source.flags & 262144 /* TypeParameter */ && getConstraintOfType(source) === target) {
63547
63547
  return -1 /* True */;
63548
63548
  }
63549
- // Try to see if we're relating something like `Foo` -> `Bar | null | undefined`.
63550
- // If so, reporting the `null` and `undefined` in the type is hardly useful.
63551
- // First, see if we're even relating an object type to a union.
63552
- // Then see if the target is stripped down to a single non-union type.
63553
- // Note
63554
- // * We actually want to remove null and undefined naively here (rather than using getNonNullableType),
63555
- // since we don't want to end up with a worse error like "`Foo` is not assignable to `NonNullable<T>`"
63556
- // when dealing with generics.
63557
- // * We also don't deal with primitive source types, since we already halt elaboration below.
63558
- if (target.flags & 1048576 /* Union */ && source.flags & 524288 /* Object */ &&
63559
- target.types.length <= 3 && maybeTypeOfKind(target, 98304 /* Nullable */)) {
63560
- var nullStrippedTarget = extractTypesOfKind(target, ~98304 /* Nullable */);
63561
- if (!(nullStrippedTarget.flags & (1048576 /* Union */ | 131072 /* Never */))) {
63562
- target = getNormalizedType(nullStrippedTarget, /*writing*/ true);
63563
- }
63564
- if (source === nullStrippedTarget)
63565
- return -1 /* True */;
63549
+ // See if we're relating a definitely non-nullable type to a union that includes null and/or undefined
63550
+ // plus a single non-nullable type. If so, remove null and/or undefined from the target type.
63551
+ if (source.flags & 470302716 /* DefinitelyNonNullable */ && target.flags & 1048576 /* Union */) {
63552
+ var types = target.types;
63553
+ var candidate = types.length === 2 && types[0].flags & 98304 /* Nullable */ ? types[1] :
63554
+ types.length === 3 && types[0].flags & 98304 /* Nullable */ && types[1].flags & 98304 /* Nullable */ ? types[2] :
63555
+ undefined;
63556
+ if (candidate && !(candidate.flags & 98304 /* Nullable */)) {
63557
+ target = getNormalizedType(candidate, /*writing*/ true);
63558
+ if (source === target)
63559
+ return -1 /* True */;
63560
+ }
63566
63561
  }
63567
63562
  if (relation === comparableRelation && !(target.flags & 131072 /* Never */) && isSimpleTypeRelatedTo(target, source, relation) ||
63568
63563
  isSimpleTypeRelatedTo(source, target, relation, reportErrors ? reportError : undefined))
63569
63564
  return -1 /* True */;
63570
- var isComparingJsxAttributes = !!(ts.getObjectFlags(source) & 2048 /* JsxAttributes */);
63571
- var isPerformingExcessPropertyChecks = !(intersectionState & 2 /* Target */) && (isObjectLiteralType(source) && ts.getObjectFlags(source) & 16384 /* FreshLiteral */);
63572
- if (isPerformingExcessPropertyChecks) {
63573
- if (hasExcessProperties(source, target, reportErrors)) {
63565
+ if (source.flags & 469499904 /* StructuredOrInstantiable */ || target.flags & 469499904 /* StructuredOrInstantiable */) {
63566
+ var isPerformingExcessPropertyChecks = !(intersectionState & 2 /* Target */) && (isObjectLiteralType(source) && ts.getObjectFlags(source) & 16384 /* FreshLiteral */);
63567
+ if (isPerformingExcessPropertyChecks) {
63568
+ if (hasExcessProperties(source, target, reportErrors)) {
63569
+ if (reportErrors) {
63570
+ reportRelationError(headMessage, source, originalTarget.aliasSymbol ? originalTarget : target);
63571
+ }
63572
+ return 0 /* False */;
63573
+ }
63574
+ }
63575
+ var isPerformingCommonPropertyChecks = relation !== comparableRelation && !(intersectionState & 2 /* Target */) &&
63576
+ source.flags & (131068 /* Primitive */ | 524288 /* Object */ | 2097152 /* Intersection */) && source !== globalObjectType &&
63577
+ target.flags & (524288 /* Object */ | 2097152 /* Intersection */) && isWeakType(target) &&
63578
+ (getPropertiesOfType(source).length > 0 || typeHasCallOrConstructSignatures(source));
63579
+ var isComparingJsxAttributes = !!(ts.getObjectFlags(source) & 2048 /* JsxAttributes */);
63580
+ if (isPerformingCommonPropertyChecks && !hasCommonProperties(source, target, isComparingJsxAttributes)) {
63574
63581
  if (reportErrors) {
63575
- reportRelationError(headMessage, source, originalTarget.aliasSymbol ? originalTarget : target);
63582
+ var sourceString = typeToString(originalSource.aliasSymbol ? originalSource : source);
63583
+ var targetString = typeToString(originalTarget.aliasSymbol ? originalTarget : target);
63584
+ var calls = getSignaturesOfType(source, 0 /* Call */);
63585
+ var constructs = getSignaturesOfType(source, 1 /* Construct */);
63586
+ if (calls.length > 0 && isRelatedTo(getReturnTypeOfSignature(calls[0]), target, 1 /* Source */, /*reportErrors*/ false) ||
63587
+ constructs.length > 0 && isRelatedTo(getReturnTypeOfSignature(constructs[0]), target, 1 /* Source */, /*reportErrors*/ false)) {
63588
+ reportError(ts.Diagnostics.Value_of_type_0_has_no_properties_in_common_with_type_1_Did_you_mean_to_call_it, sourceString, targetString);
63589
+ }
63590
+ else {
63591
+ reportError(ts.Diagnostics.Type_0_has_no_properties_in_common_with_type_1, sourceString, targetString);
63592
+ }
63576
63593
  }
63577
63594
  return 0 /* False */;
63578
63595
  }
63579
- }
63580
- var isPerformingCommonPropertyChecks = relation !== comparableRelation && !(intersectionState & 2 /* Target */) &&
63581
- source.flags & (131068 /* Primitive */ | 524288 /* Object */ | 2097152 /* Intersection */) && source !== globalObjectType &&
63582
- target.flags & (524288 /* Object */ | 2097152 /* Intersection */) && isWeakType(target) &&
63583
- (getPropertiesOfType(source).length > 0 || typeHasCallOrConstructSignatures(source));
63584
- if (isPerformingCommonPropertyChecks && !hasCommonProperties(source, target, isComparingJsxAttributes)) {
63585
- if (reportErrors) {
63586
- var sourceString = typeToString(originalSource.aliasSymbol ? originalSource : source);
63587
- var targetString = typeToString(originalTarget.aliasSymbol ? originalTarget : target);
63588
- var calls = getSignaturesOfType(source, 0 /* Call */);
63589
- var constructs = getSignaturesOfType(source, 1 /* Construct */);
63590
- if (calls.length > 0 && isRelatedTo(getReturnTypeOfSignature(calls[0]), target, 1 /* Source */, /*reportErrors*/ false) ||
63591
- constructs.length > 0 && isRelatedTo(getReturnTypeOfSignature(constructs[0]), target, 1 /* Source */, /*reportErrors*/ false)) {
63592
- reportError(ts.Diagnostics.Value_of_type_0_has_no_properties_in_common_with_type_1_Did_you_mean_to_call_it, sourceString, targetString);
63593
- }
63594
- else {
63595
- reportError(ts.Diagnostics.Type_0_has_no_properties_in_common_with_type_1, sourceString, targetString);
63596
- }
63596
+ traceUnionsOrIntersectionsTooLarge(source, target);
63597
+ var skipCaching = source.flags & 1048576 /* Union */ && source.types.length < 4 && !(target.flags & 1048576 /* Union */) ||
63598
+ target.flags & 1048576 /* Union */ && target.types.length < 4 && !(source.flags & 469499904 /* StructuredOrInstantiable */);
63599
+ var result_7 = skipCaching ?
63600
+ unionOrIntersectionRelatedTo(source, target, reportErrors, intersectionState) :
63601
+ recursiveTypeRelatedTo(source, target, reportErrors, intersectionState, recursionFlags);
63602
+ // For certain combinations involving intersections and optional, excess, or mismatched properties we need
63603
+ // an extra property check where the intersection is viewed as a single object. The following are motivating
63604
+ // examples that all should be errors, but aren't without this extra property check:
63605
+ //
63606
+ // let obj: { a: { x: string } } & { c: number } = { a: { x: 'hello', y: 2 }, c: 5 }; // Nested excess property
63607
+ //
63608
+ // declare let wrong: { a: { y: string } };
63609
+ // let weak: { a?: { x?: number } } & { c?: string } = wrong; // Nested weak object type
63610
+ //
63611
+ // function foo<T extends object>(x: { a?: string }, y: T & { a: boolean }) {
63612
+ // x = y; // Mismatched property in source intersection
63613
+ // }
63614
+ //
63615
+ // We suppress recursive intersection property checks because they can generate lots of work when relating
63616
+ // recursive intersections that are structurally similar but not exactly identical. See #37854.
63617
+ if (result_7 && !inPropertyCheck && (target.flags & 2097152 /* Intersection */ && (isPerformingExcessPropertyChecks || isPerformingCommonPropertyChecks) ||
63618
+ isNonGenericObjectType(target) && !isArrayType(target) && !isTupleType(target) && source.flags & 2097152 /* Intersection */ && getApparentType(source).flags & 3670016 /* StructuredType */ && !ts.some(source.types, function (t) { return !!(ts.getObjectFlags(t) & 524288 /* NonInferrableType */); }))) {
63619
+ inPropertyCheck = true;
63620
+ result_7 &= recursiveTypeRelatedTo(source, target, reportErrors, 4 /* PropertyCheck */, recursionFlags);
63621
+ inPropertyCheck = false;
63622
+ }
63623
+ if (result_7) {
63624
+ return result_7;
63597
63625
  }
63598
- return 0 /* False */;
63599
- }
63600
- traceUnionsOrIntersectionsTooLarge(source, target);
63601
- var result = 0 /* False */;
63602
- var saveErrorInfo = captureErrorCalculationState();
63603
- if ((source.flags & 1048576 /* Union */ || target.flags & 1048576 /* Union */) && getConstituentCount(source) * getConstituentCount(target) < 4) {
63604
- // We skip caching when source or target is a union with no more than three constituents.
63605
- result = structuredTypeRelatedTo(source, target, reportErrors, intersectionState | 8 /* UnionIntersectionCheck */);
63606
63626
  }
63607
- else if (source.flags & 3145728 /* UnionOrIntersection */ || target.flags & 3145728 /* UnionOrIntersection */) {
63608
- result = recursiveTypeRelatedTo(source, target, reportErrors, intersectionState | 8 /* UnionIntersectionCheck */, recursionFlags);
63627
+ if (reportErrors) {
63628
+ reportErrorResults(originalSource, originalTarget, source, target, headMessage);
63609
63629
  }
63610
- if (!result && !(source.flags & 1048576 /* Union */) && (source.flags & (469499904 /* StructuredOrInstantiable */) || target.flags & 469499904 /* StructuredOrInstantiable */)) {
63611
- if (result = recursiveTypeRelatedTo(source, target, reportErrors, intersectionState, recursionFlags)) {
63612
- resetErrorInfo(saveErrorInfo);
63630
+ return 0 /* False */;
63631
+ }
63632
+ function reportErrorResults(originalSource, originalTarget, source, target, headMessage) {
63633
+ var sourceHasBase = !!getSingleBaseForNonAugmentingSubtype(originalSource);
63634
+ var targetHasBase = !!getSingleBaseForNonAugmentingSubtype(originalTarget);
63635
+ source = (originalSource.aliasSymbol || sourceHasBase) ? originalSource : source;
63636
+ target = (originalTarget.aliasSymbol || targetHasBase) ? originalTarget : target;
63637
+ var maybeSuppress = overrideNextErrorInfo > 0;
63638
+ if (maybeSuppress) {
63639
+ overrideNextErrorInfo--;
63640
+ }
63641
+ if (source.flags & 524288 /* Object */ && target.flags & 524288 /* Object */) {
63642
+ var currentError = errorInfo;
63643
+ tryElaborateArrayLikeErrors(source, target, /*reportErrors*/ true);
63644
+ if (errorInfo !== currentError) {
63645
+ maybeSuppress = !!errorInfo;
63646
+ }
63647
+ }
63648
+ if (source.flags & 524288 /* Object */ && target.flags & 131068 /* Primitive */) {
63649
+ tryElaborateErrorsForPrimitivesAndObjects(source, target);
63650
+ }
63651
+ else if (source.symbol && source.flags & 524288 /* Object */ && globalObjectType === source) {
63652
+ reportError(ts.Diagnostics.The_Object_type_is_assignable_to_very_few_other_types_Did_you_mean_to_use_the_any_type_instead);
63653
+ }
63654
+ else if (ts.getObjectFlags(source) & 2048 /* JsxAttributes */ && target.flags & 2097152 /* Intersection */) {
63655
+ var targetTypes = target.types;
63656
+ var intrinsicAttributes = getJsxType(JsxNames.IntrinsicAttributes, errorNode);
63657
+ var intrinsicClassAttributes = getJsxType(JsxNames.IntrinsicClassAttributes, errorNode);
63658
+ if (!isErrorType(intrinsicAttributes) && !isErrorType(intrinsicClassAttributes) &&
63659
+ (ts.contains(targetTypes, intrinsicAttributes) || ts.contains(targetTypes, intrinsicClassAttributes))) {
63660
+ // do not report top error
63661
+ return;
63613
63662
  }
63614
63663
  }
63615
- if (!result && source.flags & (2097152 /* Intersection */ | 262144 /* TypeParameter */)) {
63616
- // The combined constraint of an intersection type is the intersection of the constraints of
63617
- // the constituents. When an intersection type contains instantiable types with union type
63618
- // constraints, there are situations where we need to examine the combined constraint. One is
63619
- // when the target is a union type. Another is when the intersection contains types belonging
63620
- // to one of the disjoint domains. For example, given type variables T and U, each with the
63621
- // constraint 'string | number', the combined constraint of 'T & U' is 'string | number' and
63622
- // we need to check this constraint against a union on the target side. Also, given a type
63623
- // variable V constrained to 'string | number', 'V & number' has a combined constraint of
63624
- // 'string & number | number & number' which reduces to just 'number'.
63625
- // This also handles type parameters, as a type parameter with a union constraint compared against a union
63626
- // needs to have its constraint hoisted into an intersection with said type parameter, this way
63627
- // the type param can be compared with itself in the target (with the influence of its constraint to match other parts)
63628
- // For example, if `T extends 1 | 2` and `U extends 2 | 3` and we compare `T & U` to `T & U & (1 | 2 | 3)`
63629
- var constraint = getEffectiveConstraintOfIntersection(source.flags & 2097152 /* Intersection */ ? source.types : [source], !!(target.flags & 1048576 /* Union */));
63630
- if (constraint && (source.flags & 2097152 /* Intersection */ || target.flags & 1048576 /* Union */)) {
63631
- if (everyType(constraint, function (c) { return c !== source; })) { // Skip comparison if expansion contains the source itself
63632
- // TODO: Stack errors so we get a pyramid for the "normal" comparison above, _and_ a second for this
63633
- if (result = isRelatedTo(constraint, target, 1 /* Source */, /*reportErrors*/ false, /*headMessage*/ undefined, intersectionState)) {
63634
- resetErrorInfo(saveErrorInfo);
63635
- }
63636
- }
63637
- }
63664
+ else {
63665
+ errorInfo = elaborateNeverIntersection(errorInfo, originalTarget);
63638
63666
  }
63639
- // For certain combinations involving intersections and optional, excess, or mismatched properties we need
63640
- // an extra property check where the intersection is viewed as a single object. The following are motivating
63641
- // examples that all should be errors, but aren't without this extra property check:
63642
- //
63643
- // let obj: { a: { x: string } } & { c: number } = { a: { x: 'hello', y: 2 }, c: 5 }; // Nested excess property
63644
- //
63645
- // declare let wrong: { a: { y: string } };
63646
- // let weak: { a?: { x?: number } } & { c?: string } = wrong; // Nested weak object type
63647
- //
63648
- // function foo<T extends object>(x: { a?: string }, y: T & { a: boolean }) {
63649
- // x = y; // Mismatched property in source intersection
63650
- // }
63651
- //
63652
- // We suppress recursive intersection property checks because they can generate lots of work when relating
63653
- // recursive intersections that are structurally similar but not exactly identical. See #37854.
63654
- if (result && !inPropertyCheck && (target.flags & 2097152 /* Intersection */ && (isPerformingExcessPropertyChecks || isPerformingCommonPropertyChecks) ||
63655
- isNonGenericObjectType(target) && !isArrayType(target) && !isTupleType(target) && source.flags & 2097152 /* Intersection */ && getApparentType(source).flags & 3670016 /* StructuredType */ && !ts.some(source.types, function (t) { return !!(ts.getObjectFlags(t) & 524288 /* NonInferrableType */); }))) {
63656
- inPropertyCheck = true;
63657
- result &= recursiveTypeRelatedTo(source, target, reportErrors, 4 /* PropertyCheck */, recursionFlags);
63658
- inPropertyCheck = false;
63659
- }
63660
- reportErrorResults(source, target, result, isComparingJsxAttributes);
63661
- return result;
63662
- function reportErrorResults(source, target, result, isComparingJsxAttributes) {
63663
- if (!result && reportErrors) {
63664
- var sourceHasBase = !!getSingleBaseForNonAugmentingSubtype(originalSource);
63665
- var targetHasBase = !!getSingleBaseForNonAugmentingSubtype(originalTarget);
63666
- source = (originalSource.aliasSymbol || sourceHasBase) ? originalSource : source;
63667
- target = (originalTarget.aliasSymbol || targetHasBase) ? originalTarget : target;
63668
- var maybeSuppress = overrideNextErrorInfo > 0;
63669
- if (maybeSuppress) {
63670
- overrideNextErrorInfo--;
63671
- }
63672
- if (source.flags & 524288 /* Object */ && target.flags & 524288 /* Object */) {
63673
- var currentError = errorInfo;
63674
- tryElaborateArrayLikeErrors(source, target, reportErrors);
63675
- if (errorInfo !== currentError) {
63676
- maybeSuppress = !!errorInfo;
63677
- }
63678
- }
63679
- if (source.flags & 524288 /* Object */ && target.flags & 131068 /* Primitive */) {
63680
- tryElaborateErrorsForPrimitivesAndObjects(source, target);
63681
- }
63682
- else if (source.symbol && source.flags & 524288 /* Object */ && globalObjectType === source) {
63683
- reportError(ts.Diagnostics.The_Object_type_is_assignable_to_very_few_other_types_Did_you_mean_to_use_the_any_type_instead);
63684
- }
63685
- else if (isComparingJsxAttributes && target.flags & 2097152 /* Intersection */) {
63686
- var targetTypes = target.types;
63687
- var intrinsicAttributes = getJsxType(JsxNames.IntrinsicAttributes, errorNode);
63688
- var intrinsicClassAttributes = getJsxType(JsxNames.IntrinsicClassAttributes, errorNode);
63689
- if (!isErrorType(intrinsicAttributes) && !isErrorType(intrinsicClassAttributes) &&
63690
- (ts.contains(targetTypes, intrinsicAttributes) || ts.contains(targetTypes, intrinsicClassAttributes))) {
63691
- // do not report top error
63692
- return result;
63693
- }
63694
- }
63695
- else {
63696
- errorInfo = elaborateNeverIntersection(errorInfo, originalTarget);
63697
- }
63698
- if (!headMessage && maybeSuppress) {
63699
- lastSkippedInfo = [source, target];
63700
- // Used by, eg, missing property checking to replace the top-level message with a more informative one
63701
- return result;
63702
- }
63703
- reportRelationError(headMessage, source, target);
63704
- }
63667
+ if (!headMessage && maybeSuppress) {
63668
+ lastSkippedInfo = [source, target];
63669
+ // Used by, eg, missing property checking to replace the top-level message with a more informative one
63670
+ return;
63705
63671
  }
63672
+ reportRelationError(headMessage, source, target);
63706
63673
  }
63707
63674
  function traceUnionsOrIntersectionsTooLarge(source, target) {
63708
63675
  if (!ts.tracing) {
@@ -63729,21 +63696,6 @@ var ts;
63729
63696
  }
63730
63697
  }
63731
63698
  }
63732
- function isIdenticalTo(source, target, recursionFlags) {
63733
- if (source.flags !== target.flags)
63734
- return 0 /* False */;
63735
- if (source.flags & 67358815 /* Singleton */)
63736
- return -1 /* True */;
63737
- traceUnionsOrIntersectionsTooLarge(source, target);
63738
- if (source.flags & 3145728 /* UnionOrIntersection */) {
63739
- var result_7 = eachTypeRelatedToSomeType(source, target);
63740
- if (result_7) {
63741
- result_7 &= eachTypeRelatedToSomeType(target, source);
63742
- }
63743
- return result_7;
63744
- }
63745
- return recursiveTypeRelatedTo(source, target, /*reportErrors*/ false, 0 /* None */, recursionFlags);
63746
- }
63747
63699
  function getTypeOfPropertyInTypes(types, name) {
63748
63700
  var appendPropType = function (propTypes, type) {
63749
63701
  var _a;
@@ -63842,6 +63794,41 @@ var ts;
63842
63794
  function shouldCheckAsExcessProperty(prop, container) {
63843
63795
  return prop.valueDeclaration && container.valueDeclaration && prop.valueDeclaration.parent === container.valueDeclaration;
63844
63796
  }
63797
+ function unionOrIntersectionRelatedTo(source, target, reportErrors, intersectionState) {
63798
+ // Note that these checks are specifically ordered to produce correct results. In particular,
63799
+ // we need to deconstruct unions before intersections (because unions are always at the top),
63800
+ // and we need to handle "each" relations before "some" relations for the same kind of type.
63801
+ if (source.flags & 1048576 /* Union */) {
63802
+ return relation === comparableRelation ?
63803
+ someTypeRelatedToType(source, target, reportErrors && !(source.flags & 131068 /* Primitive */), intersectionState) :
63804
+ eachTypeRelatedToType(source, target, reportErrors && !(source.flags & 131068 /* Primitive */), intersectionState);
63805
+ }
63806
+ if (target.flags & 1048576 /* Union */) {
63807
+ return typeRelatedToSomeType(getRegularTypeOfObjectLiteral(source), target, reportErrors && !(source.flags & 131068 /* Primitive */) && !(target.flags & 131068 /* Primitive */));
63808
+ }
63809
+ if (target.flags & 2097152 /* Intersection */) {
63810
+ return typeRelatedToEachType(getRegularTypeOfObjectLiteral(source), target, reportErrors, 2 /* Target */);
63811
+ }
63812
+ // Source is an intersection. For the comparable relation, if the target is a primitive type we hoist the
63813
+ // constraints of all non-primitive types in the source into a new intersection. We do this because the
63814
+ // intersection may further constrain the constraints of the non-primitive types. For example, given a type
63815
+ // parameter 'T extends 1 | 2', the intersection 'T & 1' should be reduced to '1' such that it doesn't
63816
+ // appear to be comparable to '2'.
63817
+ if (relation === comparableRelation && target.flags & 131068 /* Primitive */) {
63818
+ var constraints = ts.sameMap(source.types, getBaseConstraintOrType);
63819
+ if (constraints !== source.types) {
63820
+ source = getIntersectionType(constraints);
63821
+ if (!(source.flags & 2097152 /* Intersection */)) {
63822
+ return isRelatedTo(source, target, 1 /* Source */, /*reportErrors*/ false);
63823
+ }
63824
+ }
63825
+ }
63826
+ // Check to see if any constituents of the intersection are immediately related to the target.
63827
+ // Don't report errors though. Elaborating on whether a source constituent is related to the target is
63828
+ // not actually useful and leads to some confusing error messages. Instead, we rely on the caller
63829
+ // checking whether the full intersection viewed as an object is related to the target.
63830
+ return someTypeRelatedToType(source, target, /*reportErrors*/ false, 1 /* Source */);
63831
+ }
63845
63832
  function eachTypeRelatedToSomeType(source, target) {
63846
63833
  var result = -1 /* True */;
63847
63834
  var sourceTypes = source.types;
@@ -63877,8 +63864,11 @@ var ts;
63877
63864
  }
63878
63865
  }
63879
63866
  if (reportErrors) {
63867
+ // Elaborate only if we can find a best matching type in the target union
63880
63868
  var bestMatchingType = getBestMatchingType(source, target, isRelatedTo);
63881
- isRelatedTo(source, bestMatchingType || targetTypes[targetTypes.length - 1], 2 /* Target */, /*reportErrors*/ true);
63869
+ if (bestMatchingType) {
63870
+ isRelatedTo(source, bestMatchingType, 2 /* Target */, /*reportErrors*/ true);
63871
+ }
63882
63872
  }
63883
63873
  return 0 /* False */;
63884
63874
  }
@@ -64014,7 +64004,7 @@ var ts;
64014
64004
  if (overflow) {
64015
64005
  return 0 /* False */;
64016
64006
  }
64017
- var keyIntersectionState = intersectionState | (inPropertyCheck ? 16 /* InPropertyCheck */ : 0);
64007
+ var keyIntersectionState = intersectionState | (inPropertyCheck ? 8 /* InPropertyCheck */ : 0);
64018
64008
  var id = getRelationKey(source, target, keyIntersectionState, relation, /*ingnoreConstraints*/ false);
64019
64009
  var entry = relation.get(id);
64020
64010
  if (entry !== undefined) {
@@ -64082,6 +64072,7 @@ var ts;
64082
64072
  return originalHandler(onlyUnreliable);
64083
64073
  };
64084
64074
  }
64075
+ var result;
64085
64076
  if (expandingFlags === 3 /* Both */) {
64086
64077
  ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.instant("checkTypes" /* CheckTypes */, "recursiveTypeRelatedTo_DepthLimit", {
64087
64078
  sourceId: source.id,
@@ -64091,8 +64082,13 @@ var ts;
64091
64082
  depth: sourceDepth,
64092
64083
  targetDepth: targetDepth
64093
64084
  });
64085
+ result = 3 /* Maybe */;
64086
+ }
64087
+ else {
64088
+ ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.push("checkTypes" /* CheckTypes */, "structuredTypeRelatedTo", { sourceId: source.id, targetId: target.id });
64089
+ result = structuredTypeRelatedTo(source, target, reportErrors, intersectionState);
64090
+ ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.pop();
64094
64091
  }
64095
- var result = expandingFlags !== 3 /* Both */ ? structuredTypeRelatedTo(source, target, reportErrors, intersectionState) : 3 /* Maybe */;
64096
64092
  if (outofbandVarianceMarkerHandler) {
64097
64093
  outofbandVarianceMarkerHandler = originalHandler;
64098
64094
  }
@@ -64124,98 +64120,97 @@ var ts;
64124
64120
  return result;
64125
64121
  }
64126
64122
  function structuredTypeRelatedTo(source, target, reportErrors, intersectionState) {
64127
- ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.push("checkTypes" /* CheckTypes */, "structuredTypeRelatedTo", { sourceId: source.id, targetId: target.id });
64128
- var result = structuredTypeRelatedToWorker(source, target, reportErrors, intersectionState);
64129
- ts.tracing === null || ts.tracing === void 0 ? void 0 : ts.tracing.pop();
64130
- return result;
64131
- }
64132
- function structuredTypeRelatedToWorker(source, target, reportErrors, intersectionState) {
64133
64123
  if (intersectionState & 4 /* PropertyCheck */) {
64134
64124
  return propertiesRelatedTo(source, target, reportErrors, /*excludedProperties*/ undefined, 0 /* None */);
64135
64125
  }
64136
- if (intersectionState & 8 /* UnionIntersectionCheck */) {
64137
- // Note that these checks are specifically ordered to produce correct results. In particular,
64138
- // we need to deconstruct unions before intersections (because unions are always at the top),
64139
- // and we need to handle "each" relations before "some" relations for the same kind of type.
64140
- if (source.flags & 1048576 /* Union */) {
64141
- return relation === comparableRelation ?
64142
- someTypeRelatedToType(source, target, reportErrors && !(source.flags & 131068 /* Primitive */), intersectionState & ~8 /* UnionIntersectionCheck */) :
64143
- eachTypeRelatedToType(source, target, reportErrors && !(source.flags & 131068 /* Primitive */), intersectionState & ~8 /* UnionIntersectionCheck */);
64144
- }
64145
- if (target.flags & 1048576 /* Union */) {
64146
- return typeRelatedToSomeType(getRegularTypeOfObjectLiteral(source), target, reportErrors && !(source.flags & 131068 /* Primitive */) && !(target.flags & 131068 /* Primitive */));
64147
- }
64148
- if (target.flags & 2097152 /* Intersection */) {
64149
- return typeRelatedToEachType(getRegularTypeOfObjectLiteral(source), target, reportErrors, 2 /* Target */);
64150
- }
64151
- // Source is an intersection. For the comparable relation, if the target is a primitive type we hoist the
64152
- // constraints of all non-primitive types in the source into a new intersection. We do this because the
64153
- // intersection may further constrain the constraints of the non-primitive types. For example, given a type
64154
- // parameter 'T extends 1 | 2', the intersection 'T & 1' should be reduced to '1' such that it doesn't
64155
- // appear to be comparable to '2'.
64156
- if (relation === comparableRelation && target.flags & 131068 /* Primitive */) {
64157
- var constraints = ts.sameMap(source.types, getBaseConstraintOrType);
64158
- if (constraints !== source.types) {
64159
- source = getIntersectionType(constraints);
64160
- if (!(source.flags & 2097152 /* Intersection */)) {
64161
- return isRelatedTo(source, target, 1 /* Source */, /*reportErrors*/ false);
64162
- }
64126
+ var result;
64127
+ var originalErrorInfo;
64128
+ var varianceCheckFailed = false;
64129
+ var saveErrorInfo = captureErrorCalculationState();
64130
+ var sourceFlags = source.flags;
64131
+ var targetFlags = target.flags;
64132
+ if (relation === identityRelation) {
64133
+ // We've already checked that source.flags and target.flags are identical
64134
+ if (sourceFlags & 3145728 /* UnionOrIntersection */) {
64135
+ var result_8 = eachTypeRelatedToSomeType(source, target);
64136
+ if (result_8) {
64137
+ result_8 &= eachTypeRelatedToSomeType(target, source);
64163
64138
  }
64139
+ return result_8;
64164
64140
  }
64165
- // Check to see if any constituents of the intersection are immediately related to the target.
64166
- //
64167
- // Don't report errors though. Checking whether a constituent is related to the source is not actually
64168
- // useful and leads to some confusing error messages. Instead it is better to let the below checks
64169
- // take care of this, or to not elaborate at all. For instance,
64170
- //
64171
- // - For an object type (such as 'C = A & B'), users are usually more interested in structural errors.
64172
- //
64173
- // - For a union type (such as '(A | B) = (C & D)'), it's better to hold onto the whole intersection
64174
- // than to report that 'D' is not assignable to 'A' or 'B'.
64175
- //
64176
- // - For a primitive type or type parameter (such as 'number = A & B') there is no point in
64177
- // breaking the intersection apart.
64178
- return someTypeRelatedToType(source, target, /*reportErrors*/ false, 1 /* Source */);
64179
- }
64180
- var flags = source.flags & target.flags;
64181
- if (relation === identityRelation && !(flags & 524288 /* Object */)) {
64182
- if (flags & 4194304 /* Index */) {
64141
+ if (sourceFlags & 4194304 /* Index */) {
64183
64142
  return isRelatedTo(source.type, target.type, 3 /* Both */, /*reportErrors*/ false);
64184
64143
  }
64185
- var result_8 = 0 /* False */;
64186
- if (flags & 8388608 /* IndexedAccess */) {
64187
- if (result_8 = isRelatedTo(source.objectType, target.objectType, 3 /* Both */, /*reportErrors*/ false)) {
64188
- if (result_8 &= isRelatedTo(source.indexType, target.indexType, 3 /* Both */, /*reportErrors*/ false)) {
64189
- return result_8;
64144
+ if (sourceFlags & 8388608 /* IndexedAccess */) {
64145
+ if (result = isRelatedTo(source.objectType, target.objectType, 3 /* Both */, /*reportErrors*/ false)) {
64146
+ if (result &= isRelatedTo(source.indexType, target.indexType, 3 /* Both */, /*reportErrors*/ false)) {
64147
+ return result;
64190
64148
  }
64191
64149
  }
64192
64150
  }
64193
- if (flags & 16777216 /* Conditional */) {
64151
+ if (sourceFlags & 16777216 /* Conditional */) {
64194
64152
  if (source.root.isDistributive === target.root.isDistributive) {
64195
- if (result_8 = isRelatedTo(source.checkType, target.checkType, 3 /* Both */, /*reportErrors*/ false)) {
64196
- if (result_8 &= isRelatedTo(source.extendsType, target.extendsType, 3 /* Both */, /*reportErrors*/ false)) {
64197
- if (result_8 &= isRelatedTo(getTrueTypeFromConditionalType(source), getTrueTypeFromConditionalType(target), 3 /* Both */, /*reportErrors*/ false)) {
64198
- if (result_8 &= isRelatedTo(getFalseTypeFromConditionalType(source), getFalseTypeFromConditionalType(target), 3 /* Both */, /*reportErrors*/ false)) {
64199
- return result_8;
64153
+ if (result = isRelatedTo(source.checkType, target.checkType, 3 /* Both */, /*reportErrors*/ false)) {
64154
+ if (result &= isRelatedTo(source.extendsType, target.extendsType, 3 /* Both */, /*reportErrors*/ false)) {
64155
+ if (result &= isRelatedTo(getTrueTypeFromConditionalType(source), getTrueTypeFromConditionalType(target), 3 /* Both */, /*reportErrors*/ false)) {
64156
+ if (result &= isRelatedTo(getFalseTypeFromConditionalType(source), getFalseTypeFromConditionalType(target), 3 /* Both */, /*reportErrors*/ false)) {
64157
+ return result;
64200
64158
  }
64201
64159
  }
64202
64160
  }
64203
64161
  }
64204
64162
  }
64205
64163
  }
64206
- if (flags & 33554432 /* Substitution */) {
64164
+ if (sourceFlags & 33554432 /* Substitution */) {
64207
64165
  return isRelatedTo(source.substitute, target.substitute, 3 /* Both */, /*reportErrors*/ false);
64208
64166
  }
64209
- return 0 /* False */;
64167
+ if (!(sourceFlags & 524288 /* Object */)) {
64168
+ return 0 /* False */;
64169
+ }
64170
+ }
64171
+ else if (sourceFlags & 3145728 /* UnionOrIntersection */ || targetFlags & 3145728 /* UnionOrIntersection */) {
64172
+ if (result = unionOrIntersectionRelatedTo(source, target, reportErrors, intersectionState)) {
64173
+ return result;
64174
+ }
64175
+ if (source.flags & 2097152 /* Intersection */ || source.flags & 262144 /* TypeParameter */ && target.flags & 1048576 /* Union */) {
64176
+ // The combined constraint of an intersection type is the intersection of the constraints of
64177
+ // the constituents. When an intersection type contains instantiable types with union type
64178
+ // constraints, there are situations where we need to examine the combined constraint. One is
64179
+ // when the target is a union type. Another is when the intersection contains types belonging
64180
+ // to one of the disjoint domains. For example, given type variables T and U, each with the
64181
+ // constraint 'string | number', the combined constraint of 'T & U' is 'string | number' and
64182
+ // we need to check this constraint against a union on the target side. Also, given a type
64183
+ // variable V constrained to 'string | number', 'V & number' has a combined constraint of
64184
+ // 'string & number | number & number' which reduces to just 'number'.
64185
+ // This also handles type parameters, as a type parameter with a union constraint compared against a union
64186
+ // needs to have its constraint hoisted into an intersection with said type parameter, this way
64187
+ // the type param can be compared with itself in the target (with the influence of its constraint to match other parts)
64188
+ // For example, if `T extends 1 | 2` and `U extends 2 | 3` and we compare `T & U` to `T & U & (1 | 2 | 3)`
64189
+ var constraint = getEffectiveConstraintOfIntersection(source.flags & 2097152 /* Intersection */ ? source.types : [source], !!(target.flags & 1048576 /* Union */));
64190
+ if (constraint && everyType(constraint, function (c) { return c !== source; })) { // Skip comparison if expansion contains the source itself
64191
+ // TODO: Stack errors so we get a pyramid for the "normal" comparison above, _and_ a second for this
64192
+ if (result = isRelatedTo(constraint, target, 1 /* Source */, /*reportErrors*/ false, /*headMessage*/ undefined, intersectionState)) {
64193
+ resetErrorInfo(saveErrorInfo);
64194
+ return result;
64195
+ }
64196
+ }
64197
+ }
64198
+ // The ordered decomposition above doesn't handle all cases. Specifically, we also need to handle:
64199
+ // Source is instantiable (e.g. source has union or intersection constraint).
64200
+ // Source is an object, target is a union (e.g. { a, b: boolean } <=> { a, b: true } | { a, b: false }).
64201
+ // Source is an intersection, target is an object (e.g. { a } & { b } <=> { a, b }).
64202
+ // Source is an intersection, target is a union (e.g. { a } & { b: boolean } <=> { a, b: true } | { a, b: false }).
64203
+ // Source is an intersection, target instantiable (e.g. string & { tag } <=> T["a"] constrained to string & { tag }).
64204
+ if (!(sourceFlags & 465829888 /* Instantiable */ ||
64205
+ sourceFlags & 524288 /* Object */ && targetFlags & 1048576 /* Union */ ||
64206
+ sourceFlags & 2097152 /* Intersection */ && targetFlags & (524288 /* Object */ | 1048576 /* Union */ | 465829888 /* Instantiable */))) {
64207
+ return 0 /* False */;
64208
+ }
64210
64209
  }
64211
- var result;
64212
- var originalErrorInfo;
64213
- var varianceCheckFailed = false;
64214
- var saveErrorInfo = captureErrorCalculationState();
64215
64210
  // We limit alias variance probing to only object and conditional types since their alias behavior
64216
64211
  // is more predictable than other, interned types, which may or may not have an alias depending on
64217
64212
  // the order in which things were checked.
64218
- if (source.flags & (524288 /* Object */ | 16777216 /* Conditional */) && source.aliasSymbol &&
64213
+ if (sourceFlags & (524288 /* Object */ | 16777216 /* Conditional */) && source.aliasSymbol &&
64219
64214
  source.aliasTypeArguments && source.aliasSymbol === target.aliasSymbol &&
64220
64215
  !(source.aliasTypeArgumentsContainsMarker || target.aliasTypeArgumentsContainsMarker)) {
64221
64216
  var variances = getAliasVariances(source.aliasSymbol);
@@ -64233,7 +64228,7 @@ var ts;
64233
64228
  isSingleElementGenericTupleType(target) && (target.target.readonly || isMutableArrayOrTuple(getBaseConstraintOfType(source) || source)) && (result = isRelatedTo(source, getTypeArguments(target)[0], 2 /* Target */))) {
64234
64229
  return result;
64235
64230
  }
64236
- if (target.flags & 262144 /* TypeParameter */) {
64231
+ if (targetFlags & 262144 /* TypeParameter */) {
64237
64232
  // A source type { [P in Q]: X } is related to a target type T if keyof T is related to Q and X is related to T[Q].
64238
64233
  if (ts.getObjectFlags(source) & 32 /* Mapped */ && !source.declaration.nameType && isRelatedTo(getIndexType(target), getConstraintTypeFromMappedType(source), 3 /* Both */)) {
64239
64234
  if (!(getMappedTypeModifiers(source) & 4 /* IncludeOptional */)) {
@@ -64245,10 +64240,10 @@ var ts;
64245
64240
  }
64246
64241
  }
64247
64242
  }
64248
- else if (target.flags & 4194304 /* Index */) {
64243
+ else if (targetFlags & 4194304 /* Index */) {
64249
64244
  var targetType_1 = target.type;
64250
64245
  // A keyof S is related to a keyof T if T is related to S.
64251
- if (source.flags & 4194304 /* Index */) {
64246
+ if (sourceFlags & 4194304 /* Index */) {
64252
64247
  if (result = isRelatedTo(targetType_1, source.type, 3 /* Both */, /*reportErrors*/ false)) {
64253
64248
  return result;
64254
64249
  }
@@ -64299,8 +64294,8 @@ var ts;
64299
64294
  }
64300
64295
  }
64301
64296
  }
64302
- else if (target.flags & 8388608 /* IndexedAccess */) {
64303
- if (source.flags & 8388608 /* IndexedAccess */) {
64297
+ else if (targetFlags & 8388608 /* IndexedAccess */) {
64298
+ if (sourceFlags & 8388608 /* IndexedAccess */) {
64304
64299
  // Relate components directly before falling back to constraint relationships
64305
64300
  // A type S[K] is related to a type T[J] if S is related to T and K is related to J.
64306
64301
  if (result = isRelatedTo(source.objectType, target.objectType, 3 /* Both */, reportErrors)) {
@@ -64406,7 +64401,7 @@ var ts;
64406
64401
  }
64407
64402
  }
64408
64403
  }
64409
- else if (target.flags & 16777216 /* Conditional */) {
64404
+ else if (targetFlags & 16777216 /* Conditional */) {
64410
64405
  // If we reach 10 levels of nesting for the same conditional type, assume it is an infinitely expanding recursive
64411
64406
  // conditional type and bail out with a Ternary.Maybe result.
64412
64407
  if (isDeeplyNestedType(target, targetStack, targetDepth, 10)) {
@@ -64431,8 +64426,8 @@ var ts;
64431
64426
  }
64432
64427
  }
64433
64428
  }
64434
- else if (target.flags & 134217728 /* TemplateLiteral */) {
64435
- if (source.flags & 134217728 /* TemplateLiteral */) {
64429
+ else if (targetFlags & 134217728 /* TemplateLiteral */) {
64430
+ if (sourceFlags & 134217728 /* TemplateLiteral */) {
64436
64431
  if (relation === comparableRelation) {
64437
64432
  return templateLiteralTypesDefinitelyUnrelated(source, target) ? 0 /* False */ : -1 /* True */;
64438
64433
  }
@@ -64444,11 +64439,11 @@ var ts;
64444
64439
  return -1 /* True */;
64445
64440
  }
64446
64441
  }
64447
- if (source.flags & 8650752 /* TypeVariable */) {
64448
- // IndexedAccess comparisons are handled above in the `target.flags & TypeFlage.IndexedAccess` branch
64449
- if (!(source.flags & 8388608 /* IndexedAccess */ && target.flags & 8388608 /* IndexedAccess */)) {
64442
+ if (sourceFlags & 8650752 /* TypeVariable */) {
64443
+ // IndexedAccess comparisons are handled above in the `targetFlags & TypeFlage.IndexedAccess` branch
64444
+ if (!(sourceFlags & 8388608 /* IndexedAccess */ && targetFlags & 8388608 /* IndexedAccess */)) {
64450
64445
  var constraint = getConstraintOfType(source);
64451
- if (!constraint || (source.flags & 262144 /* TypeParameter */ && constraint.flags & 1 /* Any */)) {
64446
+ if (!constraint || (sourceFlags & 262144 /* TypeParameter */ && constraint.flags & 1 /* Any */)) {
64452
64447
  // A type variable with no constraint is not related to the non-primitive object type.
64453
64448
  if (result = isRelatedTo(emptyObjectType, extractTypesOfKind(target, ~67108864 /* NonPrimitive */), 3 /* Both */)) {
64454
64449
  resetErrorInfo(saveErrorInfo);
@@ -64461,7 +64456,7 @@ var ts;
64461
64456
  return result;
64462
64457
  }
64463
64458
  // slower, fuller, this-instantiated check (necessary when comparing raw `this` types from base classes), see `subclassWithPolymorphicThisIsAssignable.ts` test for example
64464
- else if (result = isRelatedTo(getTypeWithThisArgument(constraint, source), target, 1 /* Source */, reportErrors && !(target.flags & source.flags & 262144 /* TypeParameter */), /*headMessage*/ undefined, intersectionState)) {
64459
+ else if (result = isRelatedTo(getTypeWithThisArgument(constraint, source), target, 1 /* Source */, reportErrors && !(targetFlags & sourceFlags & 262144 /* TypeParameter */), /*headMessage*/ undefined, intersectionState)) {
64465
64460
  resetErrorInfo(saveErrorInfo);
64466
64461
  return result;
64467
64462
  }
@@ -64478,14 +64473,14 @@ var ts;
64478
64473
  }
64479
64474
  }
64480
64475
  }
64481
- else if (source.flags & 4194304 /* Index */) {
64476
+ else if (sourceFlags & 4194304 /* Index */) {
64482
64477
  if (result = isRelatedTo(keyofConstraintType, target, 1 /* Source */, reportErrors)) {
64483
64478
  resetErrorInfo(saveErrorInfo);
64484
64479
  return result;
64485
64480
  }
64486
64481
  }
64487
- else if (source.flags & 134217728 /* TemplateLiteral */ && !(target.flags & 524288 /* Object */)) {
64488
- if (!(target.flags & 134217728 /* TemplateLiteral */)) {
64482
+ else if (sourceFlags & 134217728 /* TemplateLiteral */ && !(targetFlags & 524288 /* Object */)) {
64483
+ if (!(targetFlags & 134217728 /* TemplateLiteral */)) {
64489
64484
  var constraint = getBaseConstraintOfType(source);
64490
64485
  if (constraint && constraint !== source && (result = isRelatedTo(constraint, target, 1 /* Source */, reportErrors))) {
64491
64486
  resetErrorInfo(saveErrorInfo);
@@ -64493,8 +64488,8 @@ var ts;
64493
64488
  }
64494
64489
  }
64495
64490
  }
64496
- else if (source.flags & 268435456 /* StringMapping */) {
64497
- if (target.flags & 268435456 /* StringMapping */ && source.symbol === target.symbol) {
64491
+ else if (sourceFlags & 268435456 /* StringMapping */) {
64492
+ if (targetFlags & 268435456 /* StringMapping */ && source.symbol === target.symbol) {
64498
64493
  if (result = isRelatedTo(source.type, target.type, 3 /* Both */, reportErrors)) {
64499
64494
  resetErrorInfo(saveErrorInfo);
64500
64495
  return result;
@@ -64508,14 +64503,14 @@ var ts;
64508
64503
  }
64509
64504
  }
64510
64505
  }
64511
- else if (source.flags & 16777216 /* Conditional */) {
64506
+ else if (sourceFlags & 16777216 /* Conditional */) {
64512
64507
  // If we reach 10 levels of nesting for the same conditional type, assume it is an infinitely expanding recursive
64513
64508
  // conditional type and bail out with a Ternary.Maybe result.
64514
64509
  if (isDeeplyNestedType(source, sourceStack, sourceDepth, 10)) {
64515
64510
  resetErrorInfo(saveErrorInfo);
64516
64511
  return 3 /* Maybe */;
64517
64512
  }
64518
- if (target.flags & 16777216 /* Conditional */) {
64513
+ if (targetFlags & 16777216 /* Conditional */) {
64519
64514
  // Two conditional types 'T1 extends U1 ? X1 : Y1' and 'T2 extends U2 ? X2 : Y2' are related if
64520
64515
  // one of T1 and T2 is related to the other, U1 and U2 are identical types, X1 is related to X2,
64521
64516
  // and Y1 is related to Y2.
@@ -64575,9 +64570,10 @@ var ts;
64575
64570
  }
64576
64571
  return 0 /* False */;
64577
64572
  }
64578
- var sourceIsPrimitive = !!(source.flags & 131068 /* Primitive */);
64573
+ var sourceIsPrimitive = !!(sourceFlags & 131068 /* Primitive */);
64579
64574
  if (relation !== identityRelation) {
64580
64575
  source = getApparentType(source);
64576
+ sourceFlags = source.flags;
64581
64577
  }
64582
64578
  else if (isGenericMappedType(source)) {
64583
64579
  return 0 /* False */;
@@ -64619,7 +64615,7 @@ var ts;
64619
64615
  // In a check of the form X = A & B, we will have previously checked if A relates to X or B relates
64620
64616
  // to X. Failing both of those we want to check if the aggregation of A and B's members structurally
64621
64617
  // relates to X. Thus, we include intersection types on the source side here.
64622
- if (source.flags & (524288 /* Object */ | 2097152 /* Intersection */) && target.flags & 524288 /* Object */) {
64618
+ if (sourceFlags & (524288 /* Object */ | 2097152 /* Intersection */) && targetFlags & 524288 /* Object */) {
64623
64619
  // Report structural errors only if we haven't reported any errors yet
64624
64620
  var reportStructuralErrors = reportErrors && errorInfo === saveErrorInfo.errorInfo && !sourceIsPrimitive;
64625
64621
  result = propertiesRelatedTo(source, target, reportStructuralErrors, /*excludedProperties*/ undefined, intersectionState);
@@ -64643,7 +64639,7 @@ var ts;
64643
64639
  // there exists a constituent of T for every combination of the discriminants of S
64644
64640
  // with respect to T. We do not report errors here, as we will use the existing
64645
64641
  // error result from checking each constituent of the union.
64646
- if (source.flags & (524288 /* Object */ | 2097152 /* Intersection */) && target.flags & 1048576 /* Union */) {
64642
+ if (sourceFlags & (524288 /* Object */ | 2097152 /* Intersection */) && targetFlags & 1048576 /* Union */) {
64647
64643
  var objectOnlyTarget = extractTypesOfKind(target, 524288 /* Object */ | 2097152 /* Intersection */ | 33554432 /* Substitution */);
64648
64644
  if (objectOnlyTarget.flags & 1048576 /* Union */) {
64649
64645
  var result_9 = typeRelatedToDiscriminatedType(source, objectOnlyTarget);
@@ -65158,7 +65154,6 @@ var ts;
65158
65154
  }
65159
65155
  }
65160
65156
  var result = -1 /* True */;
65161
- var saveErrorInfo = captureErrorCalculationState();
65162
65157
  var incompatibleReporter = kind === 1 /* Construct */ ? reportIncompatibleConstructSignatureReturn : reportIncompatibleCallSignatureReturn;
65163
65158
  var sourceObjectFlags = ts.getObjectFlags(source);
65164
65159
  var targetObjectFlags = ts.getObjectFlags(target);
@@ -65199,6 +65194,7 @@ var ts;
65199
65194
  else {
65200
65195
  outer: for (var _i = 0, targetSignatures_1 = targetSignatures; _i < targetSignatures_1.length; _i++) {
65201
65196
  var t = targetSignatures_1[_i];
65197
+ var saveErrorInfo = captureErrorCalculationState();
65202
65198
  // Only elaborate errors from the first failure
65203
65199
  var shouldElaborateErrors = reportErrors;
65204
65200
  for (var _c = 0, sourceSignatures_1 = sourceSignatures; _c < sourceSignatures_1.length; _c++) {
@@ -68369,9 +68365,6 @@ var ts;
68369
68365
  getUnionType(ts.map(type.types, mapper), 1 /* Literal */, aliasSymbol, aliasTypeArguments) :
68370
68366
  mapType(type, mapper);
68371
68367
  }
68372
- function getConstituentCount(type) {
68373
- return type.flags & 1048576 /* Union */ ? type.types.length : 1;
68374
- }
68375
68368
  function extractTypesOfKind(type, kind) {
68376
68369
  return filterType(type, function (t) { return (t.flags & kind) !== 0; });
68377
68370
  }
@@ -69945,7 +69938,7 @@ var ts;
69945
69938
  var substituteConstraints = !(checkMode && checkMode & 2 /* Inferential */) &&
69946
69939
  someType(type, isGenericTypeWithUnionConstraint) &&
69947
69940
  (isConstraintPosition(type, reference) || hasContextualTypeWithNoGenericTypes(reference, checkMode));
69948
- return substituteConstraints ? mapType(type, function (t) { return t.flags & 465829888 /* Instantiable */ && !isMappedTypeGenericIndexedAccess(t) ? getBaseConstraintOrType(t) : t; }) : type;
69941
+ return substituteConstraints ? mapType(type, function (t) { return t.flags & 465829888 /* Instantiable */ ? getBaseConstraintOrType(t) : t; }) : type;
69949
69942
  }
69950
69943
  function isExportOrExportExpression(location) {
69951
69944
  return !!ts.findAncestor(location, function (n) {
@@ -70017,6 +70010,9 @@ var ts;
70017
70010
  if (parentType && parentType.flags & 1048576 /* Union */ && !(parent.kind === 163 /* Parameter */ && isSymbolAssigned(symbol))) {
70018
70011
  var pattern = declaration.parent;
70019
70012
  var narrowedType = getFlowTypeOfReference(pattern, parentType, parentType, /*flowContainer*/ undefined, location.flowNode);
70013
+ if (narrowedType.flags & 131072 /* Never */) {
70014
+ return neverType;
70015
+ }
70020
70016
  return getBindingElementTypeFromParentType(declaration, narrowedType);
70021
70017
  }
70022
70018
  }
@@ -76037,21 +76033,22 @@ var ts;
76037
76033
  if (links.type === unknownType) {
76038
76034
  links.type = getTypeFromBindingPattern(declaration.name);
76039
76035
  }
76040
- assignBindingElementTypes(declaration.name);
76036
+ assignBindingElementTypes(declaration.name, links.type);
76041
76037
  }
76042
76038
  }
76043
76039
  }
76044
76040
  // When contextual typing assigns a type to a parameter that contains a binding pattern, we also need to push
76045
76041
  // the destructured type into the contained binding elements.
76046
- function assignBindingElementTypes(pattern) {
76042
+ function assignBindingElementTypes(pattern, parentType) {
76047
76043
  for (var _i = 0, _a = pattern.elements; _i < _a.length; _i++) {
76048
76044
  var element = _a[_i];
76049
76045
  if (!ts.isOmittedExpression(element)) {
76046
+ var type = getBindingElementTypeFromParentType(element, parentType);
76050
76047
  if (element.name.kind === 79 /* Identifier */) {
76051
- getSymbolLinks(getSymbolOfNode(element)).type = getTypeForBindingElement(element);
76048
+ getSymbolLinks(getSymbolOfNode(element)).type = type;
76052
76049
  }
76053
76050
  else {
76054
- assignBindingElementTypes(element.name);
76051
+ assignBindingElementTypes(element.name, type);
76055
76052
  }
76056
76053
  }
76057
76054
  }
@@ -79792,28 +79789,24 @@ var ts;
79792
79789
  if (returnType.flags & 1 /* Any */) {
79793
79790
  return;
79794
79791
  }
79792
+ var headMessage;
79795
79793
  var expectedReturnType;
79796
- var headMessage = getDiagnosticHeadMessageForDecoratorResolution(node);
79797
- var errorInfo;
79798
79794
  switch (node.parent.kind) {
79799
79795
  case 256 /* ClassDeclaration */:
79796
+ headMessage = ts.Diagnostics.Decorator_function_return_type_0_is_not_assignable_to_type_1;
79800
79797
  var classSymbol = getSymbolOfNode(node.parent);
79801
79798
  var classConstructorType = getTypeOfSymbol(classSymbol);
79802
79799
  expectedReturnType = getUnionType([classConstructorType, voidType]);
79803
79800
  break;
79804
- case 163 /* Parameter */:
79805
- expectedReturnType = voidType;
79806
- errorInfo = ts.chainDiagnosticMessages(
79807
- /*details*/ undefined, ts.Diagnostics.The_return_type_of_a_parameter_decorator_function_must_be_either_void_or_any);
79808
- break;
79809
79801
  case 166 /* PropertyDeclaration */:
79802
+ case 163 /* Parameter */:
79803
+ headMessage = ts.Diagnostics.Decorator_function_return_type_is_0_but_is_expected_to_be_void_or_any;
79810
79804
  expectedReturnType = voidType;
79811
- errorInfo = ts.chainDiagnosticMessages(
79812
- /*details*/ undefined, ts.Diagnostics.The_return_type_of_a_property_decorator_function_must_be_either_void_or_any);
79813
79805
  break;
79814
79806
  case 168 /* MethodDeclaration */:
79815
79807
  case 171 /* GetAccessor */:
79816
79808
  case 172 /* SetAccessor */:
79809
+ headMessage = ts.Diagnostics.Decorator_function_return_type_0_is_not_assignable_to_type_1;
79817
79810
  var methodType = getTypeOfNode(node.parent);
79818
79811
  var descriptorType = createTypedPropertyDescriptorType(methodType);
79819
79812
  expectedReturnType = getUnionType([descriptorType, voidType]);
@@ -79821,7 +79814,7 @@ var ts;
79821
79814
  default:
79822
79815
  return ts.Debug.fail();
79823
79816
  }
79824
- checkTypeAssignableTo(returnType, expectedReturnType, node, headMessage, function () { return errorInfo; });
79817
+ checkTypeAssignableTo(returnType, expectedReturnType, node, headMessage);
79825
79818
  }
79826
79819
  /**
79827
79820
  * If a TypeNode can be resolved to a value symbol imported from an external module, it is
@@ -82094,9 +82087,9 @@ var ts;
82094
82087
  var containsArguments = containsArgumentsReference(node);
82095
82088
  if (containsArguments) {
82096
82089
  var lastJSDocParam = ts.lastOrUndefined(jsdocParameters);
82097
- if (lastJSDocParam && ts.isIdentifier(lastJSDocParam.name) && lastJSDocParam.typeExpression &&
82090
+ if (isJs && lastJSDocParam && ts.isIdentifier(lastJSDocParam.name) && lastJSDocParam.typeExpression &&
82098
82091
  lastJSDocParam.typeExpression.type && !parameters.has(lastJSDocParam.name.escapedText) && !isArrayType(getTypeFromTypeNode(lastJSDocParam.typeExpression.type))) {
82099
- errorOrSuggestion(isJs, lastJSDocParam.name, ts.Diagnostics.JSDoc_param_tag_has_name_0_but_there_is_no_parameter_with_that_name_It_would_match_arguments_if_it_had_an_array_type, ts.idText(lastJSDocParam.name));
82092
+ error(lastJSDocParam.name, ts.Diagnostics.JSDoc_param_tag_has_name_0_but_there_is_no_parameter_with_that_name_It_would_match_arguments_if_it_had_an_array_type, ts.idText(lastJSDocParam.name));
82100
82093
  }
82101
82094
  }
82102
82095
  else {
@@ -82106,7 +82099,9 @@ var ts;
82106
82099
  return;
82107
82100
  }
82108
82101
  if (ts.isQualifiedName(name)) {
82109
- errorOrSuggestion(isJs, name, ts.Diagnostics.Qualified_name_0_is_not_allowed_without_a_leading_param_object_1, ts.entityNameToString(name), ts.entityNameToString(name.left));
82102
+ if (isJs) {
82103
+ error(name, ts.Diagnostics.Qualified_name_0_is_not_allowed_without_a_leading_param_object_1, ts.entityNameToString(name), ts.entityNameToString(name.left));
82104
+ }
82110
82105
  }
82111
82106
  else {
82112
82107
  errorOrSuggestion(isJs, name, ts.Diagnostics.JSDoc_param_tag_has_name_0_but_there_is_no_parameter_with_that_name, ts.idText(name));
@@ -87285,28 +87280,27 @@ var ts;
87285
87280
  }
87286
87281
  function findMostOverlappyType(source, unionTarget) {
87287
87282
  var bestMatch;
87288
- var matchingCount = 0;
87289
- for (var _i = 0, _a = unionTarget.types; _i < _a.length; _i++) {
87290
- var target = _a[_i];
87291
- var overlap = getIntersectionType([getIndexType(source), getIndexType(target)]);
87292
- if (overlap.flags & 4194304 /* Index */) {
87293
- // perfect overlap of keys
87294
- bestMatch = target;
87295
- matchingCount = Infinity;
87296
- }
87297
- else if (overlap.flags & 1048576 /* Union */) {
87298
- // We only want to account for literal types otherwise.
87299
- // If we have a union of index types, it seems likely that we
87300
- // needed to elaborate between two generic mapped types anyway.
87301
- var len = ts.length(ts.filter(overlap.types, isUnitType));
87302
- if (len >= matchingCount) {
87303
- bestMatch = target;
87304
- matchingCount = len;
87305
- }
87306
- }
87307
- else if (isUnitType(overlap) && 1 >= matchingCount) {
87308
- bestMatch = target;
87309
- matchingCount = 1;
87283
+ if (!(source.flags & (131068 /* Primitive */ | 406847488 /* InstantiablePrimitive */))) {
87284
+ var matchingCount = 0;
87285
+ for (var _i = 0, _a = unionTarget.types; _i < _a.length; _i++) {
87286
+ var target = _a[_i];
87287
+ if (!(target.flags & (131068 /* Primitive */ | 406847488 /* InstantiablePrimitive */))) {
87288
+ var overlap = getIntersectionType([getIndexType(source), getIndexType(target)]);
87289
+ if (overlap.flags & 4194304 /* Index */) {
87290
+ // perfect overlap of keys
87291
+ return target;
87292
+ }
87293
+ else if (isUnitType(overlap) || overlap.flags & 1048576 /* Union */) {
87294
+ // We only want to account for literal types otherwise.
87295
+ // If we have a union of index types, it seems likely that we
87296
+ // needed to elaborate between two generic mapped types anyway.
87297
+ var len = overlap.flags & 1048576 /* Union */ ? ts.countWhere(overlap.types, isUnitType) : 1;
87298
+ if (len >= matchingCount) {
87299
+ bestMatch = target;
87300
+ matchingCount = len;
87301
+ }
87302
+ }
87303
+ }
87310
87304
  }
87311
87305
  }
87312
87306
  return bestMatch;