@@ -1891,10 +1891,12 @@ namespace ts.Completions {
18911891 let existingMembers : readonly Declaration [ ] | undefined ;
18921892
18931893 if ( objectLikeContainer . kind === SyntaxKind . ObjectLiteralExpression ) {
1894- const instantiatedType = typeChecker . getContextualType ( objectLikeContainer ) ;
1895- const completionsType = instantiatedType && typeChecker . getContextualType ( objectLikeContainer , ContextFlags . Completions ) ;
1896- if ( ! instantiatedType || ! completionsType ) return GlobalsSearch . Fail ;
1897- isNewIdentifierLocation = hasIndexSignature ( instantiatedType || completionsType ) ;
1894+ const instantiatedType = tryGetObjectLiteralContextualType ( objectLikeContainer , typeChecker ) ;
1895+ if ( instantiatedType === undefined ) {
1896+ return GlobalsSearch . Fail ;
1897+ }
1898+ const completionsType = typeChecker . getContextualType ( objectLikeContainer , ContextFlags . Completions ) ;
1899+ isNewIdentifierLocation = hasIndexSignature ( completionsType || instantiatedType ) ;
18981900 typeMembers = getPropertiesForObjectExpression ( instantiatedType , completionsType , objectLikeContainer , typeChecker ) ;
18991901 existingMembers = objectLikeContainer . properties ;
19001902 }
@@ -2830,4 +2832,15 @@ namespace ts.Completions {
28302832 function isStaticProperty ( symbol : Symbol ) {
28312833 return ! ! ( symbol . valueDeclaration && getEffectiveModifierFlags ( symbol . valueDeclaration ) & ModifierFlags . Static && isClassLike ( symbol . valueDeclaration . parent ) ) ;
28322834 }
2835+
2836+ function tryGetObjectLiteralContextualType ( node : ObjectLiteralExpression , typeChecker : TypeChecker ) {
2837+ const type = typeChecker . getContextualType ( node ) ;
2838+ if ( type ) {
2839+ return type ;
2840+ }
2841+ if ( isBinaryExpression ( node . parent ) && node . parent . operatorToken . kind === SyntaxKind . EqualsToken ) {
2842+ return typeChecker . getTypeAtLocation ( node . parent ) ;
2843+ }
2844+ return undefined ;
2845+ }
28332846}
0 commit comments