@@ -3625,17 +3625,20 @@ function getCompletionData(
36253625 }
36263626
36273627 log ( "getCompletionData: Semantic work: " + ( timestamp ( ) - semanticStart ) ) ;
3628- const contextualType = previousToken && getContextualType ( previousToken , position , sourceFile , typeChecker ) ;
3628+ const contextualTypeOrConstraint = previousToken && (
3629+ getContextualType ( previousToken , position , sourceFile , typeChecker ) ??
3630+ getConstraintOfTypeArgumentProperty ( previousToken , typeChecker )
3631+ ) ;
36293632
36303633 // exclude literal suggestions after <input type="text" [||] /> (#51667) and after closing quote (#52675)
36313634 // for strings getStringLiteralCompletions handles completions
36323635 const isLiteralExpected = ! tryCast ( previousToken , isStringLiteralLike ) && ! isJsxIdentifierExpected ;
36333636 const literals = ! isLiteralExpected ? [ ] : mapDefined (
3634- contextualType && ( contextualType . isUnion ( ) ? contextualType . types : [ contextualType ] ) ,
3637+ contextualTypeOrConstraint && ( contextualTypeOrConstraint . isUnion ( ) ? contextualTypeOrConstraint . types : [ contextualTypeOrConstraint ] ) ,
36353638 t => t . isLiteral ( ) && ! ( t . flags & TypeFlags . EnumLiteral ) ? t . value : undefined ,
36363639 ) ;
36373640
3638- const recommendedCompletion = previousToken && contextualType && getRecommendedCompletion ( previousToken , contextualType , typeChecker ) ;
3641+ const recommendedCompletion = previousToken && contextualTypeOrConstraint && getRecommendedCompletion ( previousToken , contextualTypeOrConstraint , typeChecker ) ;
36393642 return {
36403643 kind : CompletionDataKind . Data ,
36413644 symbols,
@@ -5779,6 +5782,13 @@ function getConstraintOfTypeArgumentProperty(node: Node, checker: TypeChecker):
57795782 switch ( node . kind ) {
57805783 case SyntaxKind . PropertySignature :
57815784 return checker . getTypeOfPropertyOfContextualType ( t , ( node as PropertySignature ) . symbol . escapedName ) ;
5785+ case SyntaxKind . ColonToken :
5786+ if ( node . parent . kind === SyntaxKind . PropertySignature ) {
5787+ // The cursor is at a property value location like `Foo<{ x: | }`.
5788+ // `t` already refers to the appropriate property type.
5789+ return t ;
5790+ }
5791+ break ;
57825792 case SyntaxKind . IntersectionType :
57835793 case SyntaxKind . TypeLiteral :
57845794 case SyntaxKind . UnionType :
0 commit comments