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 — Intersection Types that have overlapping properties can fail · Issue #49264 · microsoft/TypeScript

Intersection Types that have overlapping properties can fail #49264

New issue
Copy link
New issue
Copy link
Closed
Closed
Intersection Types that have overlapping properties can fail#49264
Copy link
Labels
Working as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug

Description

@wdamien
Wes Gorgichuk (wdamien)
opened on May 26, 2022
Issue body actions

This seems to be the source: #31838

Example:
Try an intersection of 2 types where the same property has inconsistent overlapping types:

type Bar = {
    Prop: string
};

type Works = Bar & {Prop: number}; // Bar & {Prop: number}
type ThisIsNever = Bar & {Prop: null}; // never

It makes sense to me that individual types can be reduced to never, but why can intersecting types with nested overlapping property types get reduced to never?

Playground link: https://www.typescriptlang.org/play?ts=4.7.0-beta#code/C4TwDgpgBAQghgJygXigbwFBW1ACggezAC4oBnYBASwDsBzDAXwG4MMB6dqAdQIQGsyUAGa0IGUJCgBJGsAgIyEAMbAqBGiliIoAMnT4ipGgFcAtgCMFLKJ21J9aQySinL1ieGgA5CADcFWXlFFTUNLXgHA0IXGn9rZlsuSL1oo1d4hEY2O28CYCgIAA9IVQgAE08pbxMAG1qghSVVdU1UFMdnYzramzsAJRUIKgDy40ykqABREtCK0gADDrTYnsYFqAAKPiglnU6Y8YCshYBKKugAVRpyiFE48saQlvD2-ZXSExu7sXK+rkGymGoyOCkmM1K8jGu2WTkOUC+t3uFXWWx2eyicPScWO63OQA

This might be expected, but it does feel like a bug to me. My initial use case was joining a few different types together to get a union of all their keys. But since some props had a null | undefined type, it was reduced to never. Causing my use of those keys to fail unexpectedly. I would expect ThisIsNever to have a Prop: never property instead, or maybe a union of string | null. Or at-least surface an error saying the union is not possible because of Prop being incompatible.

Tested on: 4.6.4, 4.7.0-beta
This worked as expected in: v3.8.3. And starts not being expected in v3.9.7

Activity

  1. jcalz commented on May 26, 2022

    @jcalz
    Joe Calzaretta (jcalz)
    on May 26, 2022
    Contributor
    More actions

    You didn't fill out the template.

    This is working as intended as per #36696. Since TypeScript 3.9, intersections are reduced by discriminant properties. null and undefined are unit/singleton types, and a property whose member types contain at least one unit/singleton type are considered discriminant properties.

    Reacted by Andrew Branch
    Reacted by Martin Johns
  2. Andrew Branch (andrewbranch)
    added
    Working as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug
    on May 26, 2022
  3. fatcerberus commented on May 26, 2022

    @fatcerberus
    Bruce Pascoe (fatcerberus)
    on May 26, 2022
    More actions

    Shouldn’t both types reduce to never? Realistically it’s not possible to produce a value of either one.

  4. RyanCavanaugh commented on May 26, 2022

    @RyanCavanaugh
    Ryan Cavanaugh (RyanCavanaugh)
    on May 26, 2022
    Member
    More actions

    Conflicting primitives are in the grey zone between conflicting unit types and conflicting object types. It's definitely not possible to produce an intersection of two unit types, definitely is possible to produce an intersection of two object types (or at least it's not computable to determine if any two arbitrary object types have zero overlap), but intersections between two primitives sometimes arise in places that are benign.

  5. typescript-bot commented on May 29, 2022

    @typescript-bot
    TypeScript Bot (typescript-bot)
    on May 29, 2022
    Contributor
    More actions

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

  6. TypeScript Bot (typescript-bot)
    closed this as completedon May 29, 2022
  7. 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

    Working as IntendedThe behavior described is the intended behavior; this is not a bugThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — 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.