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

Literal strings with generics are inconsistant when strictNullChecks is false #50787

Open
sebastien-de-saint-florent opened this issue Sep 15, 2022 · 4 comments Β· May be fixed by #56953
Open

Literal strings with generics are inconsistant when strictNullChecks is false #50787

sebastien-de-saint-florent opened this issue Sep 15, 2022 · 4 comments Β· May be fixed by #56953
Assignees
Labels
Fix Available A PR has been opened for this issue Needs Investigation This issue needs a team member to investigate its status.

Comments

@sebastien-de-saint-florent
Copy link

sebastien-de-saint-florent commented Sep 15, 2022

Bug Report

πŸ”Ž Search Terms

  • string literal
  • strictNullChecks
  • keyof

πŸ•— Version & Regression Information

It works properly on v4.7.4 but is failing on v4.8.2 and with the nightly build.
It also works normally when strictNullChecks is true.

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

type Model = { s: string; b: boolean }
let pick: <Keys extends keyof Model>(properties: readonly Keys[]) => Pick<Model, Keys>
let transform: <T>(obj: T) => T

const result1 = transform(pick(["s"]))

const intermediate = pick(["s"])
const result2 = transform(intermediate)

πŸ™ Actual behavior

result1 has a type of Pick<Model, keyof Model> and result2 as a type of Pick<Model, "s">

πŸ™‚ Expected behavior

result1 and result2 should have the same type Pick<Model, "s">.

@ahejlsberg ahejlsberg added the Needs Investigation This issue needs a team member to investigate its status. label Sep 17, 2022
@ahejlsberg
Copy link
Member

@typescript-bot bisect good v4.7.4 bad v4.8.2

@ahejlsberg
Copy link
Member

Was broken by #49086. Manually bisected to a2b785b.

@andrewbranch
Copy link
Member

Adding a T extends {} constraint to transform makes it repro in --strictNullChecks too.

@andrewbranch
Copy link
Member

I added a fix to #50759, which needs a review. It’s the same fix for #50635, but from one additional call site.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Fix Available A PR has been opened for this issue Needs Investigation This issue needs a team member to investigate its status.
Projects
None yet
4 participants