@@ -1891,10 +1891,12 @@ namespace ts.Completions {
1891
1891
let existingMembers : readonly Declaration [ ] | undefined ;
1892
1892
1893
1893
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 ) ;
1898
1900
typeMembers = getPropertiesForObjectExpression ( instantiatedType , completionsType , objectLikeContainer , typeChecker ) ;
1899
1901
existingMembers = objectLikeContainer . properties ;
1900
1902
}
@@ -2830,4 +2832,15 @@ namespace ts.Completions {
2830
2832
function isStaticProperty ( symbol : Symbol ) {
2831
2833
return ! ! ( symbol . valueDeclaration && getEffectiveModifierFlags ( symbol . valueDeclaration ) & ModifierFlags . Static && isClassLike ( symbol . valueDeclaration . parent ) ) ;
2832
2834
}
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
+ }
2833
2846
}
0 commit comments