@@ -6564,7 +6564,7 @@ namespace ts {
65646564 // b) It references `arguments` somewhere
65656565 const lastParam = lastOrUndefined(declaration.parameters);
65666566 const lastParamTags = lastParam && getJSDocParameterTags(lastParam);
6567- const lastParamVariadicType = lastParamTags && firstDefined(lastParamTags, p =>
6567+ const lastParamVariadicType = firstDefined(lastParamTags, p =>
65686568 p.typeExpression && isJSDocVariadicType(p.typeExpression.type) ? p.typeExpression.type : undefined);
65696569 if (!lastParamVariadicType && !containsArgumentsReference(declaration)) {
65706570 return false;
@@ -9639,7 +9639,7 @@ namespace ts {
96399639 }
96409640 else if (target.flags & TypeFlags.IndexedAccess) {
96419641 // A type S is related to a type T[K] if S is related to A[K], where K is string-like and
9642- // A is the apparent type of T.
9642+ // A is the constraint of T.
96439643 const constraint = getConstraintOfIndexedAccess(<IndexedAccessType>target);
96449644 if (constraint) {
96459645 if (result = isRelatedTo(source, constraint, reportErrors)) {
@@ -9675,18 +9675,19 @@ namespace ts {
96759675 }
96769676 else if (source.flags & TypeFlags.IndexedAccess) {
96779677 // A type S[K] is related to a type T if A[K] is related to T, where K is string-like and
9678- // A is the apparent type of S.
9678+ // A is the constraint of S.
96799679 const constraint = getConstraintOfIndexedAccess(<IndexedAccessType>source);
96809680 if (constraint) {
96819681 if (result = isRelatedTo(constraint, target, reportErrors)) {
96829682 errorInfo = saveErrorInfo;
96839683 return result;
96849684 }
96859685 }
9686- else if (target.flags & TypeFlags.IndexedAccess && (<IndexedAccessType>source).indexType === (<IndexedAccessType>target).indexType) {
9687- // if we have indexed access types with identical index types, see if relationship holds for
9688- // the two object types.
9686+ else if (target.flags & TypeFlags.IndexedAccess) {
96899687 if (result = isRelatedTo((<IndexedAccessType>source).objectType, (<IndexedAccessType>target).objectType, reportErrors)) {
9688+ result &= isRelatedTo((<IndexedAccessType>source).indexType, (<IndexedAccessType>target).indexType, reportErrors);
9689+ }
9690+ if (result) {
96909691 errorInfo = saveErrorInfo;
96919692 return result;
96929693 }
@@ -10967,7 +10968,7 @@ namespace ts {
1096710968 return type === typeParameter || type.flags & TypeFlags.UnionOrIntersection && forEach((<UnionOrIntersectionType>type).types, t => isTypeParameterAtTopLevel(t, typeParameter));
1096810969 }
1096910970
10970- /** Create an object with properties named in the string literal type. Every property has type `{} ` */
10971+ /** Create an object with properties named in the string literal type. Every property has type `any ` */
1097110972 function createEmptyObjectTypeFromStringLiteral(type: Type) {
1097210973 const members = createSymbolTable();
1097310974 forEachType(type, t => {
@@ -10976,7 +10977,7 @@ namespace ts {
1097610977 }
1097710978 const name = escapeLeadingUnderscores((t as StringLiteralType).value);
1097810979 const literalProp = createSymbol(SymbolFlags.Property, name);
10979- literalProp.type = emptyObjectType ;
10980+ literalProp.type = anyType ;
1098010981 if (t.symbol) {
1098110982 literalProp.declarations = t.symbol.declarations;
1098210983 literalProp.valueDeclaration = t.symbol.valueDeclaration;
@@ -11031,7 +11032,9 @@ namespace ts {
1103111032 const templateType = getTemplateTypeFromMappedType(target);
1103211033 const inference = createInferenceInfo(typeParameter);
1103311034 inferTypes([inference], sourceType, templateType);
11034- return inference.candidates ? getUnionType(inference.candidates, UnionReduction.Subtype) : emptyObjectType;
11035+ return inference.candidates ? getUnionType(inference.candidates, UnionReduction.Subtype) :
11036+ inference.contraCandidates ? getCommonSubtype(inference.contraCandidates) :
11037+ emptyObjectType;
1103511038 }
1103611039
1103711040 function getUnmatchedProperty(source: Type, target: Type, requireOptionalProperties: boolean) {
@@ -18377,6 +18380,9 @@ namespace ts {
1837718380
1837818381 function checkObjectLiteralAssignment(node: ObjectLiteralExpression, sourceType: Type): Type {
1837918382 const properties = node.properties;
18383+ if (strictNullChecks && properties.length === 0) {
18384+ return checkNonNullType(sourceType, node);
18385+ }
1838018386 for (const p of properties) {
1838118387 checkObjectLiteralDestructuringPropertyAssignment(sourceType, p, properties);
1838218388 }
@@ -21446,7 +21452,13 @@ namespace ts {
2144621452 if (isBindingPattern(node.name)) {
2144721453 // Don't validate for-in initializer as it is already an error
2144821454 if (node.initializer && node.parent.parent.kind !== SyntaxKind.ForInStatement) {
21449- checkTypeAssignableTo(checkExpressionCached(node.initializer), getWidenedTypeForVariableLikeDeclaration(node), node, /*headMessage*/ undefined);
21455+ const initializerType = checkExpressionCached(node.initializer);
21456+ if (strictNullChecks && node.name.elements.length === 0) {
21457+ checkNonNullType(initializerType, node);
21458+ }
21459+ else {
21460+ checkTypeAssignableTo(initializerType, getWidenedTypeForVariableLikeDeclaration(node), node, /*headMessage*/ undefined);
21461+ }
2145021462 checkParameterInitializer(node);
2145121463 }
2145221464 return;
@@ -26196,14 +26208,18 @@ namespace ts {
2619626208 function checkGrammarBindingElement(node: BindingElement) {
2619726209 if (node.dotDotDotToken) {
2619826210 const elements = (<BindingPattern>node.parent).elements;
26199- if (node !== lastOrUndefined (elements)) {
26211+ if (node !== last (elements)) {
2620026212 return grammarErrorOnNode(node, Diagnostics.A_rest_element_must_be_last_in_a_destructuring_pattern);
2620126213 }
2620226214
2620326215 if (node.name.kind === SyntaxKind.ArrayBindingPattern || node.name.kind === SyntaxKind.ObjectBindingPattern) {
2620426216 return grammarErrorOnNode(node.name, Diagnostics.A_rest_element_cannot_contain_a_binding_pattern);
2620526217 }
2620626218
26219+ if (node.propertyName) {
26220+ return grammarErrorOnNode(node.name, Diagnostics.A_rest_element_cannot_have_a_property_name);
26221+ }
26222+
2620726223 if (node.initializer) {
2620826224 // Error on equals token which immediately precedes the initializer
2620926225 return grammarErrorAtPos(node, node.initializer.pos - 1, 1, Diagnostics.A_rest_element_cannot_have_an_initializer);
0 commit comments