GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — False positive: Right operand of ?? is unreachable · Issue #60614 · microsoft/TypeScript

False positive: Right operand of ?? is unreachable #60614

New issue
Copy link
New issue
Copy link
Closed
#60616
Closed
False positive: Right operand of ?? is unreachable#60614
#60616
Copy link
Labels
BugA bug in TypeScript
Milestone
Backlog

Description

@steelbrain
Anees Iqbal (steelbrain)
opened on Nov 26, 2024
Issue body actions

🔎 Search Terms

Ever since Typescript 5.6, we've been getting false positives of the nullish operand lint rule. Our codebase is littered with it so it blocks us from upgrading to the latest Typescript

🕗 Version & Regression Information

  • This changed between versions 5.5 and 5.6 (also there on latest 5.7.2)

⏯ Playground Link

https://www.typescriptlang.org/play/?#code/GYVwdgxgLglg9mABADwDwBUB8AKAzlAJxjAHNcAuRdAUwFsAHAGwEMpqBlQ4sgQQIOYBPADSIAdBIBuzRiGoVEYELQBG1AgG0AugEpK6RAB9FIRo0QBvAFCJbiAtSggCSJWcTNci6pPU27APQBiAB6iIJwIIgQzEgyuHD2dHC+iFAAFtQeKilZjMTUouAOLGwAJmmJGVkqICSiCIyCaZkOlYi4IPT0Dri4-rZBHkjF1KXUFbUkYlYAvlZWQwAicPKKcFCIAO5wBADWlAAy1MCbuDBlWTBeYD7qJmbX6VYQCPiI0rLUlEqq9wC8KFQvzUBEwAAN0jBwYgAPywxAABgWQwA6rs9rhYS83ptPnIAEyIQFoEHqCFQ8E4sDvfHUADMP2UoOJHxkhLhCORQA

💻 Code

function x<T>(strings: TemplateStringsArray, ...values: number[]): T | null {
    return null as never
    // ^ you can also remove the above line, unrelated to the bug, only there to suppress
    // an unrelated error.
}

// Does not work: Left side is never nullish
const value: number = x<number>`hi` ?? 0
// ^ this line causes an error in Typescript

// Works?
const value2 = x<number>`hi`
const value3: number = value2 ?? 0

🙁 Actual behavior

Right operand of ?? is unreachable because the left operand is never nullish

🙂 Expected behavior

No error

Additional information about the issue

I tried looking for duplicate issues but wasn't able to find any. If the bug has already been filed, a link to it would be appreciated. Thanks!

Activity

  1. jakebailey commented on Nov 26, 2024

    @jakebailey
    Jake Bailey (jakebailey)
    on Nov 26, 2024
    Member
    More actions

    This check is syntactic, so it seems like we just need to entirely ignore template expressions like this since we have no idea without type checking that a template could evaluate to a nullable thing :(

  2. steelbrain commented on Nov 26, 2024

    @steelbrain
    Anees Iqbal (steelbrain)
    on Nov 26, 2024
    Author
    More actions

    I'd prefer it being disabled on template expressions to the status quo, which is false positives. Maybe in the future we can infer more information and make it an informed check instead

  3. Ryan Cavanaugh (RyanCavanaugh)
    added
    BugA bug in TypeScript
    on Nov 26, 2024
  4. Ryan Cavanaugh (RyanCavanaugh)
    added this to the Backlog milestone on Nov 26, 2024
  5. Ryan Cavanaugh (RyanCavanaugh)
    closed this as completedin #60616on Nov 26, 2024
  6. steelbrain commented on Nov 26, 2024

    @steelbrain
    Anees Iqbal (steelbrain)
    on Nov 26, 2024
    Author
    More actions

    Impressed by the speed of execution here! Good work Team! 👏

  7. steelbrain commented on Dec 2, 2024

    @steelbrain
    Anees Iqbal (steelbrain)
    on Dec 2, 2024
    Author
    More actions

    Jake Bailey (@jakebailey) Is there going to be a 5.7.3 with this change? We're stuck on 5.5 until this fix gets released

  8. RyanCavanaugh commented on Dec 2, 2024

    @RyanCavanaugh
    Ryan Cavanaugh (RyanCavanaugh)
    on Dec 2, 2024
    Member
    More actions

    In general we wouldn't backport something like this since it's non-crashing, has a workaround, and isn't commonly reported. You can switch to nightly or ts-ignore the affected lines.

    Reacted by Anees Iqbal
  9. steelbrain commented on Dec 2, 2024

    @steelbrain
    Anees Iqbal (steelbrain)
    on Dec 2, 2024
    Author
    More actions

    Neither nightly nor ts-ignore for the hundreds of instances is a good option for us. We'll just wait it out. Thanks for the response!

  10. microsoft
    locked as resolved and limited conversation to collaborators on Oct 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScript

    Type

    No type

    Projects

    No projects

      Milestone

      • BacklogNo due date

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.