Skip to content

TS 4.8 Generics completion is now weaker. #50680

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

Closed
eretica opened this issue Sep 8, 2022 · 4 comments Β· Fixed by #50691
Closed

TS 4.8 Generics completion is now weaker. #50680

eretica opened this issue Sep 8, 2022 · 4 comments Β· Fixed by #50691
Assignees
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue

Comments

@eretica
Copy link

eretica commented Sep 8, 2022

Bug Report
πŸ”Ž Search Terms
Generics completion is now weaker.

πŸ•— Version & Regression Information
This changed between versions 4.7.4 and 4.8.2
⏯ Playground Link

πŸ’» Code

export const func = <T extends string>({ keys }: { keys: T[] }) => {

  const firstKey = keys[0];
  
  return {
    keys,
    firstKey
  } as const;
};

// 4.8.2  firstKey string
// 4.7.4  firstKey "aa" | "bb"
const { keys, firstKey } = func({keys: ["aa", "bb"]})

πŸ™ Actual behavior

4.8.2 firstKey type of string

πŸ™‚ Expected behavior
firstKey type of "aa" | "bb"

@somebody1234
Copy link

oddly enough, these both work perfectly fine...

const { keys } = func({keys: ["aa", "bb"]})
const x = func({keys: ["aa", "bb"]})

@Andarist
Copy link
Contributor

Andarist commented Sep 8, 2022

On top of that the initial autocompletion for firstKey suggests that it will be of the union type - it just becomes string after the firstKey is being added to the binding pattern and when it becomes part of the contextual node~
Screenshot 2022-09-08 at 11 53 13

I've bisected this change to #49887 by @jakebailey

@jakebailey
Copy link
Member

That's... weird. I'll take a look.

@jakebailey jakebailey added this to the TypeScript 4.9.0 milestone Sep 8, 2022
@jakebailey jakebailey self-assigned this Sep 8, 2022
@jakebailey jakebailey added the Bug A bug in TypeScript label Sep 8, 2022
@jakebailey
Copy link
Member

Ah, so this is the test case that would have caught that we really did need to do something special in getTypeFromBindingElement. No test failed when I removed what I thought was redundant code, but it turns out that this was that case.

@typescript-bot typescript-bot added the Fix Available A PR has been opened for this issue label Sep 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants