Skip to content

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

Open

Description

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">.

Activity

  1. ahejlsberg commented on Sep 17, 2022

    @ahejlsberg
    Member

    TypeScript Bot (@typescript-bot) bisect good v4.7.4 bad v4.8.2

  2. ahejlsberg commented on Sep 17, 2022

    @ahejlsberg
    Member

    Was broken by #49086. Manually bisected to a2b785b.

  3. andrewbranch commented on Sep 19, 2022

    @andrewbranch
    Member

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

  4. andrewbranch commented on Sep 19, 2022

    @andrewbranch
    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

Metadata

Metadata

Labels

Needs InvestigationThis issue needs a team member to investigate its status.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions