Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(50224): Intellisense for strings within a type's Union doesn't work properly for JSX #50231

Merged
merged 2 commits into from Aug 23, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/services/stringCompletions.ts
Expand Up @@ -241,7 +241,9 @@ namespace ts.Completions.StringCompletions {
// Get string literal completions from specialized signatures of the target
// i.e. declare function f(a: 'A');
// f("/*completion position*/")
return argumentInfo ? getStringLiteralCompletionsFromSignature(argumentInfo.invocation, node, argumentInfo, typeChecker) : fromContextualType();
if (argumentInfo) {
return getStringLiteralCompletionsFromSignature(argumentInfo.invocation, node, argumentInfo, typeChecker) || fromContextualType();
}
a-tarasyuk marked this conversation as resolved.
Show resolved Hide resolved
}
// falls through (is `require("")` or `require(""` or `import("")`)
a-tarasyuk marked this conversation as resolved.
Show resolved Hide resolved

Expand Down Expand Up @@ -283,7 +285,7 @@ namespace ts.Completions.StringCompletions {
type !== current && isLiteralTypeNode(type) && isStringLiteral(type.literal) ? type.literal.text : undefined);
}

function getStringLiteralCompletionsFromSignature(call: CallLikeExpression, arg: StringLiteralLike, argumentInfo: SignatureHelp.ArgumentInfoForCompletions, checker: TypeChecker): StringLiteralCompletionsFromTypes {
function getStringLiteralCompletionsFromSignature(call: CallLikeExpression, arg: StringLiteralLike, argumentInfo: SignatureHelp.ArgumentInfoForCompletions, checker: TypeChecker): StringLiteralCompletionsFromTypes | undefined {
let isNewIdentifier = false;
const uniques = new Map<string, true>();
const candidates: Signature[] = [];
Expand All @@ -301,8 +303,7 @@ namespace ts.Completions.StringCompletions {
isNewIdentifier = isNewIdentifier || !!(type.flags & TypeFlags.String);
return getStringLiteralTypes(type, uniques);
});

return { kind: StringLiteralCompletionKind.Types, types, isNewIdentifier };
return length(types) ? { kind: StringLiteralCompletionKind.Types, types, isNewIdentifier } : undefined;
}

function stringLiteralCompletionsFromProperties(type: Type | undefined): StringLiteralCompletionsFromProperties | undefined {
Expand Down
Expand Up @@ -4,4 +4,4 @@
////declare function f(a: string, b: number): void;
////f("/**/", 0);

verify.completions({ marker: "", exact: [], isNewIdentifierLocation: true });
verify.completions({ marker: "", exact: [], isNewIdentifierLocation: false });
@@ -0,0 +1,11 @@
/// <reference path="fourslash.ts" />

// @jsx: preserve
// @filename: /a.tsx
////type Props = { a: number } | { b: "b" };
a-tarasyuk marked this conversation as resolved.
Show resolved Hide resolved
////declare function Foo(args: Props): any
////
////const a1 = <Foo b={"/*1*/"} />
////const a2 = <Foo b="/*2*/" />

verify.completions({ marker: ["1", "2"], exact: ["b"] });