mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-07-01 11:42:55 -05:00
fix(3758): show completion for object literals in an assignment pattern (#40976)
This commit is contained in:
@@ -1891,10 +1891,12 @@ namespace ts.Completions {
|
||||
let existingMembers: readonly Declaration[] | undefined;
|
||||
|
||||
if (objectLikeContainer.kind === SyntaxKind.ObjectLiteralExpression) {
|
||||
const instantiatedType = typeChecker.getContextualType(objectLikeContainer);
|
||||
const completionsType = instantiatedType && typeChecker.getContextualType(objectLikeContainer, ContextFlags.Completions);
|
||||
if (!instantiatedType || !completionsType) return GlobalsSearch.Fail;
|
||||
isNewIdentifierLocation = hasIndexSignature(instantiatedType || completionsType);
|
||||
const instantiatedType = tryGetObjectLiteralContextualType(objectLikeContainer, typeChecker);
|
||||
if (instantiatedType === undefined) {
|
||||
return GlobalsSearch.Fail;
|
||||
}
|
||||
const completionsType = typeChecker.getContextualType(objectLikeContainer, ContextFlags.Completions);
|
||||
isNewIdentifierLocation = hasIndexSignature(completionsType || instantiatedType);
|
||||
typeMembers = getPropertiesForObjectExpression(instantiatedType, completionsType, objectLikeContainer, typeChecker);
|
||||
existingMembers = objectLikeContainer.properties;
|
||||
}
|
||||
@@ -2830,4 +2832,15 @@ namespace ts.Completions {
|
||||
function isStaticProperty(symbol: Symbol) {
|
||||
return !!(symbol.valueDeclaration && getEffectiveModifierFlags(symbol.valueDeclaration) & ModifierFlags.Static && isClassLike(symbol.valueDeclaration.parent));
|
||||
}
|
||||
|
||||
function tryGetObjectLiteralContextualType(node: ObjectLiteralExpression, typeChecker: TypeChecker) {
|
||||
const type = typeChecker.getContextualType(node);
|
||||
if (type) {
|
||||
return type;
|
||||
}
|
||||
if (isBinaryExpression(node.parent) && node.parent.operatorToken.kind === SyntaxKind.EqualsToken) {
|
||||
return typeChecker.getTypeAtLocation(node.parent);
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
|
||||
/// <reference path="fourslash.ts" />
|
||||
|
||||
////let x = { a: 1, b: 2 };
|
||||
////let y = ({ /**/ } = x, 1);
|
||||
|
||||
verify.completions({ marker: "", exact: ["a", "b"] });
|
||||
@@ -0,0 +1,7 @@
|
||||
|
||||
/// <reference path="fourslash.ts" />
|
||||
|
||||
////let x = { a: 1, b: 2 };
|
||||
////let y = ({ a, /**/ } = x, 1);
|
||||
|
||||
verify.completions({ marker: "", exact: ["b"] });
|
||||
Reference in New Issue
Block a user