@@ -3625,17 +3625,20 @@ function getCompletionData(
3625
3625
}
3626
3626
3627
3627
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
+ ) ;
3629
3632
3630
3633
// exclude literal suggestions after <input type="text" [||] /> (#51667) and after closing quote (#52675)
3631
3634
// for strings getStringLiteralCompletions handles completions
3632
3635
const isLiteralExpected = ! tryCast ( previousToken , isStringLiteralLike ) && ! isJsxIdentifierExpected ;
3633
3636
const literals = ! isLiteralExpected ? [ ] : mapDefined (
3634
- contextualType && ( contextualType . isUnion ( ) ? contextualType . types : [ contextualType ] ) ,
3637
+ contextualTypeOrConstraint && ( contextualTypeOrConstraint . isUnion ( ) ? contextualTypeOrConstraint . types : [ contextualTypeOrConstraint ] ) ,
3635
3638
t => t . isLiteral ( ) && ! ( t . flags & TypeFlags . EnumLiteral ) ? t . value : undefined ,
3636
3639
) ;
3637
3640
3638
- const recommendedCompletion = previousToken && contextualType && getRecommendedCompletion ( previousToken , contextualType , typeChecker ) ;
3641
+ const recommendedCompletion = previousToken && contextualTypeOrConstraint && getRecommendedCompletion ( previousToken , contextualTypeOrConstraint , typeChecker ) ;
3639
3642
return {
3640
3643
kind : CompletionDataKind . Data ,
3641
3644
symbols,
@@ -5779,6 +5782,13 @@ function getConstraintOfTypeArgumentProperty(node: Node, checker: TypeChecker):
5779
5782
switch ( node . kind ) {
5780
5783
case SyntaxKind . PropertySignature :
5781
5784
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 ;
5782
5792
case SyntaxKind . IntersectionType :
5783
5793
case SyntaxKind . TypeLiteral :
5784
5794
case SyntaxKind . UnionType :
0 commit comments