-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Exclude in typescript behaves differently when substitute with its definition #60973
Comments
Also to backlink, I asked the question in StackOverflow here also: https://stackoverflow.com/questions/79357300/why-exclude-in-typescript-behaves-differently-when-substitute-with-its-definitio |
This isn’t a bug, it’s the intended behavior of distributive conditional types. The suggestion at the end is a duplicate of or strongly related to #30572. |
Got it! Now that I learned about this, probably I should've opened the ticket as feature request. The part that is bothering me is that, before I was assuming type definitions and generics are Referential Transparent, which makes reasoning about coding at the type level pretty easy. I love TypeScript but honestly I'm a bit sad to learning that TypeScript type definitions are not referential transparent. I believe at least TypeScript should provide a way to distribute unions in @RyanCavanaugh , @jcalz Are there any other cases like this that we are not able to expand a generic to its definition? Is currently a way to do this inline? |
As I mentioned in the comment on that question, you could write I'm sure interested parties could collect more examples of places where you can't just substitute a type for its definition without changing behavior, but I don't have a big list in mind right now. |
🔎 Search Terms
site:github.com/microsoft/TypeScript Exclude
site:github.com/microsoft/TypeScript Exclude behaves differently
TypeScript Exclude inconsistent
TypeScript Exclude different
TypeScript Exclude behaves differently expanded
🕗 Version & Regression Information
⏯ Playground Link
https://www.typescriptlang.org/play/?#code/C4TwDgpgBAsiAq4IEYoF4qoD5QExRwGYCoAWAKFElgSXw2J1JIFYSA2crq6AfQFEAHgGMANgFcAJhAA88ADRQAqgD50UeFAiDgEAHaSAzsqgB+KHogA3CACcoALg0BubkigAlCIfGjgqDAERCWkZOERIZEVwujUoKAB6BMwSXEp3Lx8-ehoIlC0dfSNcujMLaztHEsj4+KSUnHwiEgoeT29fYGIMAG0YyIBdAt0DY36IfHNLG3sncdRa+uw8EkYyLnqYAEMQACNoLb0oAEsAWzBbAHsbU-1gKAAzS-s9S70AWgBzfTtj4ShhFtDN5TOlqJlOsxegBpE5HeZDbQjYrjSblGZVWGLZL8DweADyHi4QA
💻 Code
🙁 Actual behavior
Using "Distributive Conditional Types" in a generic type behaves differently compared to using concrete types. (Not Referential transparent)
🙂 Expected behavior
"Distributive Conditional Types" always works the same, no matter if it is being used in generic types or not.
Additional information about the issue
If "Distributive Conditional Types" should behave differently, I believe it worth providing a way for non-generic types to be able to distribute over the union type in conditional types, same as how it works in generics. Maybe having a syntax like:
The text was updated successfully, but these errors were encountered: