Skip to content

Commit a1d1a22

Browse files
committed
Make isJavascript parameters required
This is a bit wordy, but will probably prevent bugs similar to #18254 in the future.
1 parent 014f7ba commit a1d1a22

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

src/compiler/checker.ts

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6361,7 +6361,7 @@ namespace ts {
63616361
* @param typeParameters The requested type parameters.
63626362
* @param minTypeArgumentCount The minimum number of required type arguments.
63636363
*/
6364-
function fillMissingTypeArguments(typeArguments: Type[] | undefined, typeParameters: TypeParameter[] | undefined, minTypeArgumentCount: number, isJavaScript?: boolean) {
6364+
function fillMissingTypeArguments(typeArguments: Type[] | undefined, typeParameters: TypeParameter[] | undefined, minTypeArgumentCount: number, isJavaScript: boolean) {
63656365
const numTypeParameters = length(typeParameters);
63666366
if (numTypeParameters) {
63676367
const numTypeArguments = length(typeArguments);
@@ -6622,7 +6622,7 @@ namespace ts {
66226622
return anyType;
66236623
}
66246624

6625-
function getSignatureInstantiation(signature: Signature, typeArguments: Type[], isJavascript?: boolean): Signature {
6625+
function getSignatureInstantiation(signature: Signature, typeArguments: Type[], isJavascript: boolean): Signature {
66266626
typeArguments = fillMissingTypeArguments(typeArguments, signature.typeParameters, getMinTypeArgumentCount(signature.typeParameters), isJavascript);
66276627
const instantiations = signature.instantiations || (signature.instantiations = createMap<Signature>());
66286628
const id = getTypeListId(typeArguments);
@@ -6661,7 +6661,10 @@ namespace ts {
66616661
// where different generations of the same type parameter are in scope). This leads to a lot of new type
66626662
// identities, and potentially a lot of work comparing those identities, so here we create an instantiation
66636663
// that uses the original type identities for all unconstrained type parameters.
6664-
return getSignatureInstantiation(signature, map(signature.typeParameters, tp => tp.target && !getConstraintOfTypeParameter(tp.target) ? tp.target : tp));
6664+
return getSignatureInstantiation(
6665+
signature,
6666+
map(signature.typeParameters, tp => tp.target && !getConstraintOfTypeParameter(tp.target) ? tp.target : tp),
6667+
isInJavaScriptFile(signature.declaration));
66656668
}
66666669

66676670
function getOrCreateTypeFromSignature(signature: Signature): ObjectType {
@@ -6843,7 +6846,7 @@ namespace ts {
68436846
const id = getTypeListId(typeArguments);
68446847
let instantiation = links.instantiations.get(id);
68456848
if (!instantiation) {
6846-
links.instantiations.set(id, instantiation = instantiateType(type, createTypeMapper(typeParameters, fillMissingTypeArguments(typeArguments, typeParameters, getMinTypeArgumentCount(typeParameters)))));
6849+
links.instantiations.set(id, instantiation = instantiateType(type, createTypeMapper(typeParameters, fillMissingTypeArguments(typeArguments, typeParameters, getMinTypeArgumentCount(typeParameters), isInJavaScriptFile(symbol.valueDeclaration)))));
68476850
}
68486851
return instantiation;
68496852
}
@@ -13999,8 +14002,9 @@ namespace ts {
1399914002
const instantiatedSignatures = [];
1400014003
for (const signature of signatures) {
1400114004
if (signature.typeParameters) {
14002-
const typeArguments = fillMissingTypeArguments(/*typeArguments*/ undefined, signature.typeParameters, /*minTypeArgumentCount*/ 0);
14003-
instantiatedSignatures.push(getSignatureInstantiation(signature, typeArguments));
14005+
const isJavascript = isInJavaScriptFile(node);
14006+
const typeArguments = fillMissingTypeArguments(/*typeArguments*/ undefined, signature.typeParameters, /*minTypeArgumentCount*/ 0, isJavascript);
14007+
instantiatedSignatures.push(getSignatureInstantiation(signature, typeArguments, isJavascript));
1400414008
}
1400514009
else {
1400614010
instantiatedSignatures.push(signature);
@@ -15257,7 +15261,7 @@ namespace ts {
1525715261
if (!contextualMapper) {
1525815262
inferTypes(context.inferences, getReturnTypeOfSignature(contextualSignature), getReturnTypeOfSignature(signature), InferencePriority.ReturnType);
1525915263
}
15260-
return getSignatureInstantiation(signature, getInferredTypes(context));
15264+
return getSignatureInstantiation(signature, getInferredTypes(context), isInJavaScriptFile(contextualSignature.declaration));
1526115265
}
1526215266

1526315267
function inferTypeArguments(node: CallLikeExpression, signature: Signature, args: ReadonlyArray<Expression>, excludeArgument: boolean[], context: InferenceContext): Type[] {
@@ -15292,7 +15296,7 @@ namespace ts {
1529215296
// Above, the type of the 'value' parameter is inferred to be 'A'.
1529315297
const contextualSignature = getSingleCallSignature(instantiatedType);
1529415298
const inferenceSourceType = contextualSignature && contextualSignature.typeParameters ?
15295-
getOrCreateTypeFromSignature(getSignatureInstantiation(contextualSignature, contextualSignature.typeParameters)) :
15299+
getOrCreateTypeFromSignature(getSignatureInstantiation(contextualSignature, contextualSignature.typeParameters, isInJavaScriptFile(node))) :
1529615300
instantiatedType;
1529715301
const inferenceTargetType = getReturnTypeOfSignature(signature);
1529815302
// Inferences made from return types have lower priority than all other inferences.
@@ -16008,8 +16012,9 @@ namespace ts {
1600816012
candidate = originalCandidate;
1600916013
if (candidate.typeParameters) {
1601016014
let typeArgumentTypes: Type[];
16015+
const isJavascript = isInJavaScriptFile(candidate.declaration);
1601116016
if (typeArguments) {
16012-
typeArgumentTypes = fillMissingTypeArguments(map(typeArguments, getTypeFromTypeNode), candidate.typeParameters, getMinTypeArgumentCount(candidate.typeParameters));
16017+
typeArgumentTypes = fillMissingTypeArguments(map(typeArguments, getTypeFromTypeNode), candidate.typeParameters, getMinTypeArgumentCount(candidate.typeParameters), isJavascript);
1601316018
if (!checkTypeArguments(candidate, typeArguments, typeArgumentTypes, /*reportErrors*/ false)) {
1601416019
candidateForTypeArgumentError = originalCandidate;
1601516020
break;
@@ -16018,7 +16023,7 @@ namespace ts {
1601816023
else {
1601916024
typeArgumentTypes = inferTypeArguments(node, candidate, args, excludeArgument, inferenceContext);
1602016025
}
16021-
candidate = getSignatureInstantiation(candidate, typeArgumentTypes);
16026+
candidate = getSignatureInstantiation(candidate, typeArgumentTypes, isJavascript);
1602216027
}
1602316028
if (!checkApplicableSignature(node, args, candidate, relation, excludeArgument, /*reportErrors*/ false)) {
1602416029
candidateForArgumentError = candidate;
@@ -18782,7 +18787,7 @@ namespace ts {
1878218787
const constraint = getConstraintOfTypeParameter(typeParameters[i]);
1878318788
if (constraint) {
1878418789
if (!typeArguments) {
18785-
typeArguments = fillMissingTypeArguments(map(typeArgumentNodes, getTypeFromTypeNode), typeParameters, minTypeArgumentCount);
18790+
typeArguments = fillMissingTypeArguments(map(typeArgumentNodes, getTypeFromTypeNode), typeParameters, minTypeArgumentCount, isInJavaScriptFile(typeArgumentNodes[i]));
1878618791
mapper = createTypeMapper(typeParameters, typeArguments);
1878718792
}
1878818793
const typeArgument = typeArguments[i];

src/compiler/utilities.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1325,11 +1325,11 @@ namespace ts {
13251325
return isInJavaScriptFile(file);
13261326
}
13271327

1328-
export function isInJavaScriptFile(node: Node): boolean {
1328+
export function isInJavaScriptFile(node: Node | undefined): boolean {
13291329
return node && !!(node.flags & NodeFlags.JavaScriptFile);
13301330
}
13311331

1332-
export function isInJSDoc(node: Node): boolean {
1332+
export function isInJSDoc(node: Node | undefined): boolean {
13331333
return node && !!(node.flags & NodeFlags.JSDoc);
13341334
}
13351335

0 commit comments

Comments
 (0)