Skip to content

"Special" intersections (such as string & {}) are no longer order-independent since 4.8Β #53043

Description

Bug Report

πŸ”Ž Search Terms

string autocomplete catch all intersection special

πŸ•— Version & Regression Information

  • This changed between versions 4.7 and 4.8

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

declare function a(arg: 'test' | (string & {})): void
a('') // try string completions here
declare function b(arg: 'test' | ({} & string)): void
b('') // try string completions here

πŸ™ Actual behavior

Since 4.8 the second function doesn't provide completions despite using an intersection with the same members as the first one.

πŸ™‚ Expected behavior

I would expect both to behave the same, regardless of the order of the intersection members.

Activity

  1. fatcerberus commented on Mar 1, 2023

    @fatcerberus

    Was looking for the dupe for like 10 minutes because I knew this had come up very recently. Felt stupid when I finally realized it was your own PR.

  2. andrewbranch commented on Mar 1, 2023

    @andrewbranch
    Member

    I’m pretty sure I recall Anders saying this was intentional, though #49119 doesn’t say outright.

  3. Andarist commented on Mar 2, 2023

    @Andarist
    ContributorAuthor

    Ye, at the end of the day - I don't think this is a big deal. However, I actually lost like 15 minutes of my life, scratching my head why this thing doesn't work - only to realize later that I've written those two in reverse order. A general rule of thumb is that the order of the intersection shouldn't matter, right?

  4. jakebailey commented on Mar 2, 2023

    @jakebailey
    Member

    A general rule of thumb is that the order of the intersection shouldn't matter, right?

    This is what I thought, and I spent a bunch of time trying to make them sorted, but it does matter for overload ordering and that can affect basically anything. I can't think of any reason for it to matter for explicitly just string & {} though.

    That being said, it seems cheap to just compare them both ways.

  5. RyanCavanaugh commented on Mar 2, 2023

    @RyanCavanaugh
    Member

    Anders Hejlsberg (@ahejlsberg) any specific thoughts?

  6. RyanCavanaugh commented on Mar 2, 2023

    @RyanCavanaugh
    Member

    Very close to making a specific "Not sure if bug, but Andarist can certainly send a PR if interested" label...

  7. jakebailey commented on Mar 2, 2023

    @jakebailey
    Member

    Too late: #52782

  8. ahejlsberg commented on Mar 2, 2023

    @ahejlsberg
    Member

    I don't feel strongly about fixing this, but the fix certainly looks fine to me.

  9. ahejlsberg commented on Mar 2, 2023

    @ahejlsberg
    Member

    That said, we should of course run the full battery of tests on the fix to make sure it doesn't break anything.

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

    Experimentation NeededSomeone needs to try this out to see what happensSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions