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

autocomplete workaround for string literal inside template literal stopped working since v5.3.3 #57902

Open
GrtDev opened this issue Mar 22, 2024 · 7 comments
Labels
Cursed? It's likely this is extremely difficult to fix without making something else much, much worse Domain: Completion Lists The issue relates to showing completion lists in an editor Help Wanted You can do this Possible Improvement The current behavior isn't wrong, but it's possible to see that it might be better in some cases
Milestone

Comments

@GrtDev
Copy link

GrtDev commented Mar 22, 2024

πŸ”Ž Search Terms

string literal autocomplete template

πŸ•— Version & Regression Information

  • This changed between versions 5.3.2 and 5.3.3

⏯ Playground Link

https://www.typescriptlang.org/play?ts=5.3.3#code/C4TwDgpgBAYg9nKBeKByA9AMwaqAfNLBdALgEsATXAgAyLnQBIBvAZ2ACcyA7AcygBkUZgF8RNAFASAxnG7soAIwCGHEvEQpUqIA

πŸ’» Code

type Foo = '/foo' | '/foo/:id' | `/foo/${string & {}}`

const bar:Foo = ''

πŸ™ Actual behavior

bar only gives /foo as a suggestion.

πŸ™‚ Expected behavior

bar gives /foo and /foo/:id as a suggestion.

Additional information about the issue

I understand that the autocomplete is a longer ongoing issue in combination with string literals. However there was a workaround described in (among other places): #29729

This workaround (string & {}) still works as long as it is not inside a template literal. But stopped working inside a template literal since v5.3.3.

@Andarist
Copy link
Contributor

Andarist commented Mar 22, 2024

This one works today:

type Foo = '/foo' | '/foo/:id' | (`/foo/${string}` & {})

const bar: Foo = ''

It likely has changed in #56434

@jakebailey
Copy link
Member

Yes, that was the intended change for people to make:

image

Of course, that doesn't work before TS 5.3. See also #54188 (#56434 was in 5.4 which "finalized" the behavior).

@RyanCavanaugh RyanCavanaugh added Domain: Completion Lists The issue relates to showing completion lists in an editor Possible Improvement The current behavior isn't wrong, but it's possible to see that it might be better in some cases labels Mar 22, 2024
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Mar 22, 2024
@RyanCavanaugh RyanCavanaugh added the Help Wanted You can do this label Mar 22, 2024
@RyanCavanaugh
Copy link
Member

Would accept a (very) non-invasive/non-impactful PR to allow both workarounds to work

@jakebailey
Copy link
Member

My understanding from the design meeting discussions surrounding #56434 (#56450 ?) is that doing that was a problem as it involved traversing deeply into the elements (which I originally added but Anders removed?)

@RyanCavanaugh
Copy link
Member

What's the right tag for "PRs accepted but you'll likely have to be more clever than the entire TS team to figure it out"...

@jakebailey
Copy link
Member

cursed

@RyanCavanaugh RyanCavanaugh added the Cursed? It's likely this is extremely difficult to fix without making something else much, much worse label Mar 22, 2024
@fatcerberus
Copy link

The Cursed? tag doesn't get used often so it's always a hoot when I see it. I love that it exists.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Cursed? It's likely this is extremely difficult to fix without making something else much, much worse Domain: Completion Lists The issue relates to showing completion lists in an editor Help Wanted You can do this Possible Improvement The current behavior isn't wrong, but it's possible to see that it might be better in some cases
Projects
None yet
Development

No branches or pull requests

5 participants