Skip to content

5.1 regression: true is inferred as boolean and not assignable to true in complex types #54541

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
ImRodry opened this issue Jun 5, 2023 · 5 comments
Labels
Duplicate An existing issue was already created

Comments

@ImRodry
Copy link

ImRodry commented Jun 5, 2023

Bug Report

πŸ”Ž Search Terms

  • 5.1
  • inference
  • boolean

πŸ•— Version & Regression Information

  • This changed between versions 5.0.4 and 5.1.3

⏯ Playground Link

Playground link with relevant code

Sidenote about the snippet used: I noticed this bug while using the mongodb package and was not able to reproduce it with standalone types. This package uses very complicated types so I couldn't determine where the error was coming from, what I can tell is that it only starts happening when we use two or more interfaces in a union in the collection() call that have the same property with different string literals (in this case property "a" exists in interfaces A and B and has the value "a" in A and "b" in B). Although this template says not to use external libraries, I believe this is still a bug with TS as it is incorrectly inferring the type of the object passed to $unset. If anyone can reproduce this bug without using the package and explain why it happens I'd appreciate it a lot! This was also discussed on the TS Discord server: https://canary.discord.com/channels/508357248330760243/1114908480235651102

πŸ’» Code

import { Db } from "mongodb"

declare const db: Db

db.collection<A | B>("abc").updateOne({ foo: "bar" }, { $unset: { foo: true } })

interface A {
    a: "a"
    b: string
}

interface B {
    a: "b"
    c: string
}

πŸ™ Actual behavior

The type of the values of the object is inferred as a generic boolean, which is not compatible with true

πŸ™‚ Expected behavior

Like in v5.0.4, an object of strings mapped to the constant value true should be assignable to the type required by the function which is true | "" | 1.

@nmain
Copy link

nmain commented Jun 7, 2023

The proposed fix in #54498 fixes this as well.

@ImRodry
Copy link
Author

ImRodry commented Jun 7, 2023

Thanks! That does seem to be way more detailed. I’ll await the PR

@gabritto gabritto assigned gabritto and unassigned gabritto Jun 9, 2023
@gabritto gabritto added the Duplicate An existing issue was already created label Jun 9, 2023
@gabritto
Copy link
Member

gabritto commented Jun 9, 2023

This seems to be a duplicate of #54498.

@ImRodry
Copy link
Author

ImRodry commented Jun 10, 2023

yes I’m just waiting for the PR

@typescript-bot
Copy link
Collaborator

This issue has been marked as 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

@typescript-bot typescript-bot closed this as not planned Won't fix, can't repro, duplicate, stale Jun 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants