Skip to content

Conversation

@Andarist
Copy link
Contributor

fixes #49680 , cc @andrewbranch

@typescript-bot typescript-bot added the For Milestone Bug PRs that fix a bug with a specific milestone label Feb 27, 2023
return type.isUnion() ? flatMap(type.types, t => getStringLiteralTypes(t, uniques)) :
type.isStringLiteral() && !(type.flags & TypeFlags.EnumLiteral) && addToSeen(uniques, type.value) ? [type] : emptyArray;
return type.isUnion() ? flatMap(type.types, t => getStringLiteralTypes(t, uniques, alreadyTyped)) :
type.isStringLiteral() && !(type.flags & TypeFlags.EnumLiteral) && type.value.startsWith(alreadyTyped) && addToSeen(uniques, type.value) ? [type] : emptyArray;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on those few test failures it seems that I can't just simply discard the already matched strings at this stage. Those are still useful for creating replacement spans here:

replacementSpan: getReplacementSpanForContextToken(contextToken)

However, I'm not exactly sure what is the relation between what is being returned by TS and what is displayed by VS Code. VS code tends to skip some completions... like even if we take a look at the added test case: before this change TS returns "a" | "b" but VS Code doesn't display anything.

The goal behind this change here was for the logic to fallback to the fromContextualType() here:

return argumentInfo && getStringLiteralCompletionsFromSignature(argumentInfo.invocation, node, argumentInfo, typeChecker) || fromContextualType();

I tried to avoid doing both requests unconditionally and concatenating their results but perhaps that is the way to go here? Or perhaps this filtering should happen on a different level (like before doing the second request) but it doesn't affect the returned types? Maybe it should just test out if anything "interesting" was returned from the first request?

@Andarist
Copy link
Contributor Author

Andarist commented Jan 7, 2024

This was superseded by #54121

@Andarist Andarist closed this Jan 7, 2024
@Andarist Andarist deleted the fix/string-completions-from-conditional-types branch January 7, 2024 20:25
@microsoft microsoft locked as resolved and limited conversation to collaborators Oct 16, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

For Milestone Bug PRs that fix a bug with a specific milestone

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

with infer in template string, suggestion works in 4.6, but not work in 4.7

3 participants