mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-30 01:04:49 -05:00
Provide string completions for in keyword checks (#60272)
This commit is contained in:
committed by
GitHub
parent
0d016920e6
commit
b95187d1ce
@@ -12,6 +12,7 @@ import {
|
||||
addToSeen,
|
||||
altDirectorySeparator,
|
||||
arrayFrom,
|
||||
BinaryExpression,
|
||||
CallLikeExpression,
|
||||
CancellationToken,
|
||||
CaseClause,
|
||||
@@ -491,7 +492,17 @@ function getStringLiteralCompletionEntries(sourceFile: SourceFile, node: StringL
|
||||
const existing = new Set(namedImportsOrExports.elements.map(n => moduleExportNameTextEscaped(n.propertyName || n.name)));
|
||||
const uniques = exports.filter(e => e.escapedName !== InternalSymbolName.Default && !existing.has(e.escapedName));
|
||||
return { kind: StringLiteralCompletionKind.Properties, symbols: uniques, hasIndexSignature: false };
|
||||
|
||||
case SyntaxKind.BinaryExpression:
|
||||
if ((parent as BinaryExpression).operatorToken.kind === SyntaxKind.InKeyword) {
|
||||
const type = typeChecker.getTypeAtLocation((parent as BinaryExpression).right);
|
||||
const properties = type.isUnion() ? typeChecker.getAllPossiblePropertiesOfTypes(type.types) : type.getApparentProperties();
|
||||
return {
|
||||
kind: StringLiteralCompletionKind.Properties,
|
||||
symbols: properties.filter(prop => !prop.valueDeclaration || !isPrivateIdentifierClassElementDeclaration(prop.valueDeclaration)),
|
||||
hasIndexSignature: false,
|
||||
};
|
||||
}
|
||||
return fromContextualType(ContextFlags.None);
|
||||
default:
|
||||
return fromContextualType() || fromContextualType(ContextFlags.None);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user