-
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
Inconsistent type calculation results caused by caching mechanism #56813
Comments
We can override the type Exclude1<T,U> = T extends U ? (<A>() => (A extends T ? 1 : 2)) extends (<A>() => (A extends U ? 1 : 2)) ? never : T : T |
Such inconsistency is the price one pays for ducking beneath the caution tape and wandering around. The internal representation of a conceptually unordered structure like a union is supposed to be unobservable. If there’s a bug here it’s that you can observe it, not that the observation is inconsistent: Unless there’s an example that doesn’t involve an intentionally unsupported use case, I expect this to be closed as “won’t fix” or “not a defect” or “by design” or “skrt swerve” or whatever the lingo is nowadays. |
In fact, I don't care about the order of the union types here, I just want the caching mechanism to work properly. |
If you don't care about the order then your code shouldn't depend on being able to pull the "last" element out of a union type. If you are using |
Union order is not supposed to be observable. If you manage to build something that does observe union ordering, well, stop doing that (but congrats on finding something - it's not easy!). Breaking things on purpose does not constitute a bug 🫠 |
sigh😮💨 |
@NWYLZW Take heed that your I personally wouldn’t touch anything that looks like |
Yes, indeed, this issue arises when converting a union type into an intersection type because using function overloading to obtain the last type in the union type leads to this uncertain problem. However, in my case, I only need to 'pop' a type out of the union type, so I mentioned that I don't really care about the order. I just want the types to be processed one after another. |
🔎 Search Terms
🕗 Version & Regression Information
⏯ Playground Link
https://www.typescriptlang.org/play?ts=4.6.4#code/KYDwDg9gTgLgBDAnmYcCqAmAkgHjQPjgF44AKNOUGYAOwBMBnOAQxsTgH4yBrALnQCUxQgDcIASzpx+NYCOBQhVWozKk+ccTQBmCuFiFFREukK5ZpcWfKgAoJCjgAZZgxhYaaGuIg08hEkxcWzh0ShBqeiYAVxpuGggAdxpOMhB+NENCAAZLawVbQmUotP4tXShnLLhskNSnOpk5AtBIWARkVEwAFTwAGmdXeBIXNw8vHz8CALgAbTQAXXDI1Vn8qAW6rlnN0P5ZgDojnpwAURAAYwAbaLpgfsG3fHwB0ZhN2wB6T47HbtzAhhelBgMw6L4ruwdnAAD5zGjRAC2ACMFAt8F8ft9QnAAHoceydODdACMxHQQJwsxJSzhswwtPhSNRGwx2NC+NsQA
💻 Code
🙁 Actual behavior
When the same value is passed into the type calculation function, the calculation result will be affected by the previous line of code.
When we comment or uncomment, the calculation result of the next line type function will change accordingly.
🙂 Expected behavior
I think our cache data is being misused here, and I hope that the result of the calculation here should be uniquely determinable regardless of the rest of the code, instead of like it is now.
Additional information about the issue
No response
The text was updated successfully, but these errors were encountered: