Skip to content

in operator on T & object narrows to neverย #50639

Closed

Description

Bug Report

๐Ÿ”Ž Search Terms

  • in operator
  • generic
  • intersection
  • object
  • never

๐Ÿ•— Version & Regression Information

  • This changed between versions 4.7 and 4.8

โฏ Playground Link

Playground link with relevant code

๐Ÿ’ป Code

const f3 = <A,>(value: A) => {
    if (
        typeof value === "object" &&
        value !== null &&
        "prop" in value
    ) {
        value;
        // ^?
        // TS 4.7: `A`
        // TS 4.8: `never`
        // Expected: `A & object`
    }
};

๐Ÿ™ Actual behavior

See above.

๐Ÿ™‚ Expected behavior

See above.


Activity

  1. erheron commented on Sep 6, 2022

    @erheron

    It's quite interesting though, since if you remove the "prop" in value condition if, value is inferred as A & object as expected ๐Ÿค”

  2. OliverJAsh commented on Sep 6, 2022

    @OliverJAsh
    ContributorAuthor

    Note that even in TS 4.7 using the in operator on A & object returned never: https://www.typescriptlang.org/play?ts=4.7.4#code/MYewdgzgLgBAZgJhgXhgHgIIBoB8AKANwEMAbAVwFMAuGDGAMhhACMArC4KAShRxgG8AUDBEwAlnBh5ho2QCIADgCcQCueLAxi5CjJE8hs2dsoBuPUYD0lmAD0A-BYC+gp6aA. This only became an issue after TS 4.8 started narrowing A to A & object.

  3. fatcerberus commented on Sep 6, 2022

    @fatcerberus

    Since this involves narrowing via in, this might be related to #50531.

  4. andrewbranch commented on Sep 6, 2022

    @andrewbranch
    Member

    Yes, related to #50531, but not going to be fixed for 4.8.3. 4.8.3 will contain a more minimal fix specific to unknown and {}, while for 4.9 we plan to fix the other examples you show here. Anders Hejlsberg (@ahejlsberg) is actively working on this. Iโ€™m not sure thereโ€™s an existing issue tracking it though, so I guess this is it now.

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

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions