Cherry-pick PR #46614 into release-4.5 (#46675)

Component commits:
e77514a53b Add failing test.

3c0d51b3ed Check for type parameters on the original type when asking for the type argument constraint.

e7c8095935 Update tests/cases/fourslash/stringLiteralTypeCompletionsInTypeArgForNonGeneric1.ts

Co-authored-by: Daniel Rosenwasser <drosen@microsoft.com>
This commit is contained in:
TypeScript Bot
2021-11-03 15:07:23 -07:00
committed by GitHub
co-authored by Daniel Rosenwasser
parent e4a2494065
commit 0651bd3ada
2 changed files with 12 additions and 1 deletions
+2 -1
View File
@@ -34730,7 +34730,8 @@ namespace ts {
function getTypeArgumentConstraint(node: TypeNode): Type | undefined {
const typeReferenceNode = tryCast(node.parent, isTypeReferenceType);
if (!typeReferenceNode) return undefined;
const typeParameters = getTypeParametersForTypeReference(typeReferenceNode)!; // TODO: GH#18217
const typeParameters = getTypeParametersForTypeReference(typeReferenceNode);
if (!typeParameters) return undefined;
const constraint = getConstraintOfTypeParameter(typeParameters[typeReferenceNode.typeArguments!.indexOf(node)]);
return constraint && instantiateType(constraint, createTypeMapper(typeParameters, getEffectiveTypeArguments(typeReferenceNode, typeParameters)));
}
@@ -0,0 +1,10 @@
/// <reference path="./fourslash.ts" />
////interface Foo {}
////type Bar = {};
////
////let x: Foo<"/*1*/">;
////let y: Bar<"/*2*/">;
verify.completions({ marker: test.markers() });