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

TypeScript incorrectly infers logical operation result type with empty string #45951

Open
metsawyr opened this issue Sep 18, 2021 · 0 comments
Open
Labels
Bug A bug in TypeScript
Milestone

Comments

@metsawyr
Copy link

metsawyr commented Sep 18, 2021

πŸ”Ž Search Terms

string logical disjunction type inference string logical inference type infer empty string logical operation type

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

const str: string | undefined = ''

const test = (str || undefined) && {some: 'thing'}

πŸ™ Actual behavior

Inferred type of operation is

"" | {
    some: string;
} | undefined

πŸ™‚ Expected behavior

Inferred type of operation is

{
    some: string;
} | undefined

because (str || undefined) prevents empty string to be returned

@andrewbranch andrewbranch added the Bug A bug in TypeScript label Sep 23, 2021
@andrewbranch andrewbranch added this to the Backlog milestone Sep 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript
Projects
None yet
Development

No branches or pull requests

2 participants