Closed NWYLZW closed 8 months ago
On a side note, T0
should be written as
type T0 = (1 | 2 | '3') & number
because &
has higher precedence than |
.
Working as intended. https://www.typescriptlang.org/docs/handbook/2/conditional-types.html#distributive-conditional-types
Yes, I've seen this. So is this true even in the else
branch? Here, this looks very strange.
So is this true even in the
else
branch?
Yes. Distribution is over the entire conditional type, not individual branches. In other words it runs the ternary conditional expression once for each member of the union and then reassembles it at the end.
This does what you want:
export type Collect0<T, U> = [T] extends [[]] ? never : [T & U]
You are faster than me, haha.
A little weird, but I get it, thanks for your help.
🔎 Search Terms
🕗 Version & Regression Information
⏯ Playground Link
https://www.typescriptlang.org/play?#code/KYDwDg9gTgLgBDAnmYcDCEA2ngGMYAMAPACoA0cAqgHxwC8cJcoMwAdgCYDOcA2gLpwA-HDbAAbsChwAXHyYAyKvwBQoSLATJUGbHhgBGUhRr15cJZVUqkKRgTMAKA3AA+cAExu4AcgDMPgCUFqIArgC2AEZSKgD0sXCJAHpCNtqMLgy6OPjELu5e7n7ePgAsPhRsEdFQ1HEJyam2qCReWVg5hkT5nt7F7mUVYVFSdfGJcCkqQA
💻 Code
🙁 Actual behavior
🙂 Expected behavior
Additional information about the issue
No response