@@ -2985,21 +2985,32 @@ namespace ts {
2985
2985
}
2986
2986
2987
2987
function tryGetGlobalSymbols ( ) : boolean {
2988
- let containingObjectLiteral = < ObjectLiteralExpression > getContainingObjectLiteralOrBindingPatternIfApplicableForCompletion ( contextToken ) ;
2989
- if ( containingObjectLiteral && containingObjectLiteral . kind === SyntaxKind . ObjectLiteralExpression ) {
2988
+ let objectLikeContainer = getContainingObjectLiteralOrBindingPatternIfApplicableForCompletion ( contextToken ) ;
2989
+ if ( objectLikeContainer ) {
2990
2990
// Object literal expression, look up possible property names from contextual type
2991
2991
isMemberCompletion = true ;
2992
2992
isNewIdentifierLocation = true ;
2993
2993
2994
- let contextualType = typeChecker . getContextualType ( containingObjectLiteral ) ;
2995
- if ( ! contextualType ) {
2994
+ let typeForObject : Type ;
2995
+ let existingMembers : Declaration [ ] ;
2996
+
2997
+ if ( objectLikeContainer . kind === SyntaxKind . ObjectLiteralExpression ) {
2998
+ typeForObject = typeChecker . getContextualType ( < ObjectLiteralExpression > objectLikeContainer ) ;
2999
+ existingMembers = ( < ObjectLiteralExpression > objectLikeContainer ) . properties ;
3000
+ }
3001
+ else {
3002
+ typeForObject = typeChecker . getTypeAtLocation ( objectLikeContainer ) ;
3003
+ existingMembers = ( < BindingPattern > objectLikeContainer ) . elements ;
3004
+ }
3005
+
3006
+ if ( ! typeForObject ) {
2996
3007
return false ;
2997
3008
}
2998
3009
2999
- let contextualTypeMembers = typeChecker . getPropertiesOfType ( contextualType ) ;
3000
- if ( contextualTypeMembers && contextualTypeMembers . length > 0 ) {
3010
+ let typeMembers = typeChecker . getPropertiesOfType ( typeForObject ) ;
3011
+ if ( typeMembers && typeMembers . length > 0 ) {
3001
3012
// Add filtered items to the completion list
3002
- symbols = filterContextualMembersList ( contextualTypeMembers , containingObjectLiteral . properties ) ;
3013
+ symbols = filterContextualMembersList ( typeMembers , existingMembers ) ;
3003
3014
}
3004
3015
}
3005
3016
else if ( getAncestor ( contextToken , SyntaxKind . ImportClause ) ) {
@@ -3235,8 +3246,7 @@ namespace ts {
3235
3246
containingNodeKind === SyntaxKind . ClassDeclaration || // class A<T, |
3236
3247
containingNodeKind === SyntaxKind . FunctionDeclaration || // function A<T, |
3237
3248
containingNodeKind === SyntaxKind . InterfaceDeclaration || // interface A<T, |
3238
- containingNodeKind === SyntaxKind . ArrayBindingPattern || // var [x, y|
3239
- containingNodeKind === SyntaxKind . ObjectBindingPattern ; // function func({ x, y|
3249
+ containingNodeKind === SyntaxKind . ArrayBindingPattern ; // var [x, y|
3240
3250
3241
3251
case SyntaxKind . DotToken :
3242
3252
return containingNodeKind === SyntaxKind . ArrayBindingPattern ; // var [.|
@@ -3254,8 +3264,7 @@ namespace ts {
3254
3264
case SyntaxKind . OpenBraceToken :
3255
3265
return containingNodeKind === SyntaxKind . EnumDeclaration || // enum a { |
3256
3266
containingNodeKind === SyntaxKind . InterfaceDeclaration || // interface a { |
3257
- containingNodeKind === SyntaxKind . TypeLiteral || // let x : { |
3258
- containingNodeKind === SyntaxKind . ObjectBindingPattern ; // function func({ x|
3267
+ containingNodeKind === SyntaxKind . TypeLiteral ; // let x : { |
3259
3268
3260
3269
case SyntaxKind . SemicolonToken :
3261
3270
return containingNodeKind === SyntaxKind . PropertySignature &&
0 commit comments