Skip to content

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

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
Andarist opened this issue Mar 1, 2023 · 9 comments Β· Fixed by #52782
Closed
Labels
Experimentation Needed Someone needs to try this out to see what happens Suggestion An idea for TypeScript
Milestone

Comments

@Andarist
Copy link
Contributor

Andarist commented Mar 1, 2023

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.

@fatcerberus
Copy link

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.

@andrewbranch
Copy link
Member

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

@Andarist
Copy link
Contributor Author

Andarist commented Mar 2, 2023

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?

@jakebailey
Copy link
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.

@RyanCavanaugh
Copy link
Member

@ahejlsberg any specific thoughts?

@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Mar 2, 2023
@RyanCavanaugh
Copy link
Member

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

@RyanCavanaugh RyanCavanaugh added Suggestion An idea for TypeScript Experimentation Needed Someone needs to try this out to see what happens labels Mar 2, 2023
@jakebailey
Copy link
Member

Too late: #52782

@ahejlsberg
Copy link
Member

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

@ahejlsberg
Copy link
Member

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

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Experimentation Needed Someone needs to try this out to see what happens Suggestion An idea for TypeScript
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants