@@ -4916,7 +4916,7 @@ namespace ts {
4916
4916
function getInstantiatedConstructorsForTypeArguments(type: Type, typeArgumentNodes: ReadonlyArray<TypeNode>, location: Node): Signature[] {
4917
4917
const signatures = getConstructorsForTypeArguments(type, typeArgumentNodes, location);
4918
4918
const typeArguments = map(typeArgumentNodes, getTypeFromTypeNode);
4919
- return sameMap(signatures, sig => some(sig.typeParameters) ? getSignatureInstantiation(sig, typeArguments) : sig);
4919
+ return sameMap(signatures, sig => some(sig.typeParameters) ? getSignatureInstantiation(sig, typeArguments, isInJavaScriptFile(location) ) : sig);
4920
4920
}
4921
4921
4922
4922
/**
@@ -5512,7 +5512,7 @@ namespace ts {
5512
5512
const minTypeArgumentCount = getMinTypeArgumentCount(baseSig.typeParameters);
5513
5513
const typeParamCount = length(baseSig.typeParameters);
5514
5514
if ((isJavaScript || typeArgCount >= minTypeArgumentCount) && typeArgCount <= typeParamCount) {
5515
- const sig = typeParamCount ? createSignatureInstantiation(baseSig, fillMissingTypeArguments(typeArguments, baseSig.typeParameters, minTypeArgumentCount, baseTypeNode )) : cloneSignature(baseSig);
5515
+ const sig = typeParamCount ? createSignatureInstantiation(baseSig, fillMissingTypeArguments(typeArguments, baseSig.typeParameters, minTypeArgumentCount, isJavaScript )) : cloneSignature(baseSig);
5516
5516
sig.typeParameters = classType.localTypeParameters;
5517
5517
sig.resolvedReturnType = classType;
5518
5518
result.push(sig);
@@ -6371,11 +6371,10 @@ namespace ts {
6371
6371
* @param typeParameters The requested type parameters.
6372
6372
* @param minTypeArgumentCount The minimum number of required type arguments.
6373
6373
*/
6374
- function fillMissingTypeArguments(typeArguments: Type[] | undefined, typeParameters: TypeParameter[] | undefined, minTypeArgumentCount: number, location?: Node ) {
6374
+ function fillMissingTypeArguments(typeArguments: Type[] | undefined, typeParameters: TypeParameter[] | undefined, minTypeArgumentCount: number, isJavaScript: boolean ) {
6375
6375
const numTypeParameters = length(typeParameters);
6376
6376
if (numTypeParameters) {
6377
6377
const numTypeArguments = length(typeArguments);
6378
- const isJavaScript = isInJavaScriptFile(location);
6379
6378
if ((isJavaScript || numTypeArguments >= minTypeArgumentCount) && numTypeArguments <= numTypeParameters) {
6380
6379
if (!typeArguments) {
6381
6380
typeArguments = [];
@@ -6633,8 +6632,8 @@ namespace ts {
6633
6632
return anyType;
6634
6633
}
6635
6634
6636
- function getSignatureInstantiation(signature: Signature, typeArguments: Type[]): Signature {
6637
- typeArguments = fillMissingTypeArguments(typeArguments, signature.typeParameters, getMinTypeArgumentCount(signature.typeParameters));
6635
+ function getSignatureInstantiation(signature: Signature, typeArguments: Type[], isJavascript: boolean ): Signature {
6636
+ typeArguments = fillMissingTypeArguments(typeArguments, signature.typeParameters, getMinTypeArgumentCount(signature.typeParameters), isJavascript );
6638
6637
const instantiations = signature.instantiations || (signature.instantiations = createMap<Signature>());
6639
6638
const id = getTypeListId(typeArguments);
6640
6639
let instantiation = instantiations.get(id);
@@ -6672,7 +6671,10 @@ namespace ts {
6672
6671
// where different generations of the same type parameter are in scope). This leads to a lot of new type
6673
6672
// identities, and potentially a lot of work comparing those identities, so here we create an instantiation
6674
6673
// that uses the original type identities for all unconstrained type parameters.
6675
- return getSignatureInstantiation(signature, map(signature.typeParameters, tp => tp.target && !getConstraintOfTypeParameter(tp.target) ? tp.target : tp));
6674
+ return getSignatureInstantiation(
6675
+ signature,
6676
+ map(signature.typeParameters, tp => tp.target && !getConstraintOfTypeParameter(tp.target) ? tp.target : tp),
6677
+ isInJavaScriptFile(signature.declaration));
6676
6678
}
6677
6679
6678
6680
function getOrCreateTypeFromSignature(signature: Signature): ObjectType {
@@ -6823,7 +6825,8 @@ namespace ts {
6823
6825
if (typeParameters) {
6824
6826
const numTypeArguments = length(node.typeArguments);
6825
6827
const minTypeArgumentCount = getMinTypeArgumentCount(typeParameters);
6826
- if (!isInJavaScriptFile(node) && (numTypeArguments < minTypeArgumentCount || numTypeArguments > typeParameters.length)) {
6828
+ const isJavascript = isInJavaScriptFile(node);
6829
+ if (!isJavascript && (numTypeArguments < minTypeArgumentCount || numTypeArguments > typeParameters.length)) {
6827
6830
error(node,
6828
6831
minTypeArgumentCount === typeParameters.length
6829
6832
? Diagnostics.Generic_type_0_requires_1_type_argument_s
@@ -6836,7 +6839,7 @@ namespace ts {
6836
6839
// In a type reference, the outer type parameters of the referenced class or interface are automatically
6837
6840
// supplied as type arguments and the type reference only specifies arguments for the local type parameters
6838
6841
// of the class or interface.
6839
- const typeArguments = concatenate(type.outerTypeParameters, fillMissingTypeArguments(typeArgs, typeParameters, minTypeArgumentCount, node ));
6842
+ const typeArguments = concatenate(type.outerTypeParameters, fillMissingTypeArguments(typeArgs, typeParameters, minTypeArgumentCount, isJavascript ));
6840
6843
return createTypeReference(<GenericType>type, typeArguments);
6841
6844
}
6842
6845
if (node.typeArguments) {
@@ -6853,7 +6856,7 @@ namespace ts {
6853
6856
const id = getTypeListId(typeArguments);
6854
6857
let instantiation = links.instantiations.get(id);
6855
6858
if (!instantiation) {
6856
- links.instantiations.set(id, instantiation = instantiateType(type, createTypeMapper(typeParameters, fillMissingTypeArguments(typeArguments, typeParameters, getMinTypeArgumentCount(typeParameters)))));
6859
+ links.instantiations.set(id, instantiation = instantiateType(type, createTypeMapper(typeParameters, fillMissingTypeArguments(typeArguments, typeParameters, getMinTypeArgumentCount(typeParameters), isInJavaScriptFile(symbol.valueDeclaration) ))));
6857
6860
}
6858
6861
return instantiation;
6859
6862
}
@@ -14054,8 +14057,9 @@ namespace ts {
14054
14057
const instantiatedSignatures = [];
14055
14058
for (const signature of signatures) {
14056
14059
if (signature.typeParameters) {
14057
- const typeArguments = fillMissingTypeArguments(/*typeArguments*/ undefined, signature.typeParameters, /*minTypeArgumentCount*/ 0);
14058
- instantiatedSignatures.push(getSignatureInstantiation(signature, typeArguments));
14060
+ const isJavascript = isInJavaScriptFile(node);
14061
+ const typeArguments = fillMissingTypeArguments(/*typeArguments*/ undefined, signature.typeParameters, /*minTypeArgumentCount*/ 0, isJavascript);
14062
+ instantiatedSignatures.push(getSignatureInstantiation(signature, typeArguments, isJavascript));
14059
14063
}
14060
14064
else {
14061
14065
instantiatedSignatures.push(signature);
@@ -15325,7 +15329,7 @@ namespace ts {
15325
15329
if (!contextualMapper) {
15326
15330
inferTypes(context.inferences, getReturnTypeOfSignature(contextualSignature), getReturnTypeOfSignature(signature), InferencePriority.ReturnType);
15327
15331
}
15328
- return getSignatureInstantiation(signature, getInferredTypes(context));
15332
+ return getSignatureInstantiation(signature, getInferredTypes(context), isInJavaScriptFile(contextualSignature.declaration) );
15329
15333
}
15330
15334
15331
15335
function inferTypeArguments(node: CallLikeExpression, signature: Signature, args: ReadonlyArray<Expression>, excludeArgument: boolean[], context: InferenceContext): Type[] {
@@ -15360,7 +15364,7 @@ namespace ts {
15360
15364
// Above, the type of the 'value' parameter is inferred to be 'A'.
15361
15365
const contextualSignature = getSingleCallSignature(instantiatedType);
15362
15366
const inferenceSourceType = contextualSignature && contextualSignature.typeParameters ?
15363
- getOrCreateTypeFromSignature(getSignatureInstantiation(contextualSignature, contextualSignature.typeParameters)) :
15367
+ getOrCreateTypeFromSignature(getSignatureInstantiation(contextualSignature, contextualSignature.typeParameters, isInJavaScriptFile(node) )) :
15364
15368
instantiatedType;
15365
15369
const inferenceTargetType = getReturnTypeOfSignature(signature);
15366
15370
// Inferences made from return types have lower priority than all other inferences.
@@ -16076,8 +16080,9 @@ namespace ts {
16076
16080
candidate = originalCandidate;
16077
16081
if (candidate.typeParameters) {
16078
16082
let typeArgumentTypes: Type[];
16083
+ const isJavascript = isInJavaScriptFile(candidate.declaration);
16079
16084
if (typeArguments) {
16080
- typeArgumentTypes = fillMissingTypeArguments(map(typeArguments, getTypeFromTypeNode), candidate.typeParameters, getMinTypeArgumentCount(candidate.typeParameters));
16085
+ typeArgumentTypes = fillMissingTypeArguments(map(typeArguments, getTypeFromTypeNode), candidate.typeParameters, getMinTypeArgumentCount(candidate.typeParameters), isJavascript );
16081
16086
if (!checkTypeArguments(candidate, typeArguments, typeArgumentTypes, /*reportErrors*/ false)) {
16082
16087
candidateForTypeArgumentError = originalCandidate;
16083
16088
break;
@@ -16086,7 +16091,7 @@ namespace ts {
16086
16091
else {
16087
16092
typeArgumentTypes = inferTypeArguments(node, candidate, args, excludeArgument, inferenceContext);
16088
16093
}
16089
- candidate = getSignatureInstantiation(candidate, typeArgumentTypes);
16094
+ candidate = getSignatureInstantiation(candidate, typeArgumentTypes, isJavascript );
16090
16095
}
16091
16096
if (!checkApplicableSignature(node, args, candidate, relation, excludeArgument, /*reportErrors*/ false)) {
16092
16097
candidateForArgumentError = candidate;
@@ -18850,7 +18855,7 @@ namespace ts {
18850
18855
const constraint = getConstraintOfTypeParameter(typeParameters[i]);
18851
18856
if (constraint) {
18852
18857
if (!typeArguments) {
18853
- typeArguments = fillMissingTypeArguments(map(typeArgumentNodes, getTypeFromTypeNode), typeParameters, minTypeArgumentCount);
18858
+ typeArguments = fillMissingTypeArguments(map(typeArgumentNodes, getTypeFromTypeNode), typeParameters, minTypeArgumentCount, isInJavaScriptFile(typeArgumentNodes[i]) );
18854
18859
mapper = createTypeMapper(typeParameters, typeArguments);
18855
18860
}
18856
18861
const typeArgument = typeArguments[i];
0 commit comments