@@ -268,8 +268,8 @@ namespace ts {
268268 getSuggestionForNonexistentSymbol: (location, name, meaning) => getSuggestionForNonexistentSymbol(location, escapeLeadingUnderscores(name), meaning),
269269 getBaseConstraintOfType,
270270 getDefaultFromTypeParameter: type => type && type.flags & TypeFlags.TypeParameter ? getDefaultFromTypeParameter(type as TypeParameter) : undefined,
271- resolveName(name, location, meaning) {
272- return resolveName(location, escapeLeadingUnderscores(name), meaning, /*nameNotFoundMessage*/ undefined, /*nameArg*/ undefined, /*isUse*/ false);
271+ resolveName(name, location, meaning, excludeGlobals ) {
272+ return resolveName(location, escapeLeadingUnderscores(name), meaning, /*nameNotFoundMessage*/ undefined, /*nameArg*/ undefined, /*isUse*/ false, excludeGlobals );
273273 },
274274 getJsxNamespace: () => unescapeLeadingUnderscores(getJsxNamespace()),
275275 getAccessibleSymbolChain,
@@ -952,8 +952,9 @@ namespace ts {
952952 nameNotFoundMessage: DiagnosticMessage | undefined,
953953 nameArg: __String | Identifier,
954954 isUse: boolean,
955+ excludeGlobals = false,
955956 suggestedNameNotFoundMessage?: DiagnosticMessage): Symbol {
956- return resolveNameHelper(location, name, meaning, nameNotFoundMessage, nameArg, isUse, getSymbol, suggestedNameNotFoundMessage);
957+ return resolveNameHelper(location, name, meaning, nameNotFoundMessage, nameArg, isUse, excludeGlobals, getSymbol, suggestedNameNotFoundMessage);
957958 }
958959
959960 function resolveNameHelper(
@@ -963,6 +964,7 @@ namespace ts {
963964 nameNotFoundMessage: DiagnosticMessage,
964965 nameArg: __String | Identifier,
965966 isUse: boolean,
967+ excludeGlobals: boolean,
966968 lookup: typeof getSymbol,
967969 suggestedNameNotFoundMessage?: DiagnosticMessage): Symbol {
968970 const originalLocation = location; // needed for did-you-mean error reporting, which gathers candidates starting from the original location
@@ -1209,7 +1211,9 @@ namespace ts {
12091211 }
12101212 }
12111213
1212- result = lookup(globals, name, meaning);
1214+ if (!excludeGlobals) {
1215+ result = lookup(globals, name, meaning);
1216+ }
12131217 }
12141218
12151219 if (!result) {
@@ -11277,6 +11281,9 @@ namespace ts {
1127711281 }
1127811282 diagnostic = Diagnostics._0_which_lacks_return_type_annotation_implicitly_has_an_1_return_type;
1127911283 break;
11284+ case SyntaxKind.MappedType:
11285+ error(declaration, Diagnostics.Mapped_object_type_implicitly_has_an_any_template_type);
11286+ return;
1128011287 default:
1128111288 diagnostic = Diagnostics.Variable_0_implicitly_has_an_1_type;
1128211289 }
@@ -11889,6 +11896,7 @@ namespace ts {
1188911896 Diagnostics.Cannot_find_name_0,
1189011897 node,
1189111898 !isWriteOnlyAccess(node),
11899+ /*excludeGlobals*/ false,
1189211900 Diagnostics.Cannot_find_name_0_Did_you_mean_1) || unknownSymbol;
1189311901 }
1189411902 return links.resolvedSymbol;
@@ -15154,7 +15162,7 @@ namespace ts {
1515415162 * element is not a class element, or the class element type cannot be determined, returns 'undefined'.
1515515163 * For example, in the element <MyClass>, the element instance type is `MyClass` (not `typeof MyClass`).
1515615164 */
15157- function getJsxElementInstanceType(node: JsxOpeningLikeElement, valueType: Type, sourceAttributesType: Type) {
15165+ function getJsxElementInstanceType(node: JsxOpeningLikeElement, valueType: Type, sourceAttributesType: Type | undefined ) {
1515815166 Debug.assert(!(valueType.flags & TypeFlags.Union));
1515915167 if (isTypeAny(valueType)) {
1516015168 // Short-circuit if the class tag is using an element type 'any'
@@ -15173,20 +15181,27 @@ namespace ts {
1517315181 }
1517415182 }
1517515183
15176- const instantiatedSignatures = [];
15177- for (const signature of signatures) {
15178- if (signature.typeParameters) {
15179- const isJavascript = isInJavaScriptFile(node);
15180- const inferenceContext = createInferenceContext(signature, /*flags*/ isJavascript ? InferenceFlags.AnyDefault : 0);
15181- const typeArguments = inferJsxTypeArguments(signature, sourceAttributesType, inferenceContext);
15182- instantiatedSignatures.push(getSignatureInstantiation(signature, typeArguments, isJavascript));
15183- }
15184- else {
15185- instantiatedSignatures.push(signature);
15184+ if (sourceAttributesType) {
15185+ // Instantiate in context of source type
15186+ const instantiatedSignatures = [];
15187+ for (const signature of signatures) {
15188+ if (signature.typeParameters) {
15189+ const isJavascript = isInJavaScriptFile(node);
15190+ const inferenceContext = createInferenceContext(signature, /*flags*/ isJavascript ? InferenceFlags.AnyDefault : 0);
15191+ const typeArguments = inferJsxTypeArguments(signature, sourceAttributesType, inferenceContext);
15192+ instantiatedSignatures.push(getSignatureInstantiation(signature, typeArguments, isJavascript));
15193+ }
15194+ else {
15195+ instantiatedSignatures.push(signature);
15196+ }
1518615197 }
15187- }
1518815198
15189- return getUnionType(map(instantiatedSignatures, getReturnTypeOfSignature), UnionReduction.Subtype);
15199+ return getUnionType(map(instantiatedSignatures, getReturnTypeOfSignature), UnionReduction.Subtype);
15200+ }
15201+ else {
15202+ // Do not instantiate if no source type is provided - type parameters and their constraints will be used by contextual typing
15203+ return getUnionType(map(signatures, getReturnTypeOfSignature), UnionReduction.Subtype);
15204+ }
1519015205 }
1519115206
1519215207 /**
@@ -15410,7 +15425,7 @@ namespace ts {
1541015425 }
1541115426
1541215427 // Get the element instance type (the result of newing or invoking this tag)
15413- const elemInstanceType = getJsxElementInstanceType(openingLikeElement, elementType, sourceAttributesType || emptyObjectType );
15428+ const elemInstanceType = getJsxElementInstanceType(openingLikeElement, elementType, sourceAttributesType);
1541415429
1541515430 // If we should include all stateless attributes type, then get all attributes type from all stateless function signature.
1541615431 // Otherwise get only attributes type from the signature picked by choose-overload logic.
@@ -16068,7 +16083,7 @@ namespace ts {
1606816083
1606916084 function getSuggestionForNonexistentSymbol(location: Node, outerName: __String, meaning: SymbolFlags): string {
1607016085 Debug.assert(outerName !== undefined, "outername should always be defined");
16071- const result = resolveNameHelper(location, outerName, meaning, /*nameNotFoundMessage*/ undefined, outerName, /*isUse*/ false, (symbols, name, meaning) => {
16086+ const result = resolveNameHelper(location, outerName, meaning, /*nameNotFoundMessage*/ undefined, outerName, /*isUse*/ false, /*excludeGlobals*/ false, (symbols, name, meaning) => {
1607216087 Debug.assertEqual(outerName, name, "name should equal outerName");
1607316088 const symbol = getSymbol(symbols, name, meaning);
1607416089 // Sometimes the symbol is found when location is a return type of a function: `typeof x` and `x` is declared in the body of the function
@@ -20307,6 +20322,11 @@ namespace ts {
2030720322 function checkMappedType(node: MappedTypeNode) {
2030820323 checkSourceElement(node.typeParameter);
2030920324 checkSourceElement(node.type);
20325+
20326+ if (noImplicitAny && !node.type) {
20327+ reportImplicitAnyError(node, anyType);
20328+ }
20329+
2031020330 const type = <MappedType>getTypeFromMappedTypeNode(node);
2031120331 const constraintType = getConstraintTypeFromMappedType(type);
2031220332 checkTypeAssignableTo(constraintType, stringType, node.typeParameter.constraint);
@@ -22985,7 +23005,7 @@ namespace ts {
2298523005 Diagnostics.Property_0_in_type_1_is_not_assignable_to_the_same_property_in_base_type_2,
2298623006 unescapeLeadingUnderscores(declaredProp.escapedName),
2298723007 typeToString(typeWithThis),
22988- typeToString(getTypeOfSymbol(baseProp) )
23008+ typeToString(baseWithThis )
2298923009 );
2299023010 if (!checkTypeAssignableTo(getTypeOfSymbol(prop), getTypeOfSymbol(baseProp), member.name || member, /*message*/ undefined, rootChain)) {
2299123011 issuedMemberError = true;
0 commit comments