Bug Report
🔎 Search Terms
conditional type, extends, infer, spread, tuple
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about extends
⏯ Playground Link
Playground link with relevant code
💻 Code
typeFoo<K,Textendsreadonlyunknown[]>=Textendsreadonly[any, ...infer Xextendsreadonlyunknown[]] ? X : never;typeBar<K,Textendsreadonlyunknown[]>=Textendsreadonly[any, ...infer XextendsreadonlyK[]] ? X : never;typeBaz<K,Textendsreadonlyunknown[]>=Textendsreadonly[any, ...infer Xextendsreadonly(K|"a"|"b")[]] ? X : never;typex=Foo<"a"|"b",["a","b","b"]>// ^? - type x = ["b", "b"]typey=Bar<"a"|"b",["a","b","b"]>// ^? - type y = readonly ("a" | "b")[]typez=Baz<"a"|"b",["a","b","b"]>// ^? - type z = ["b", "b"]🙁 Actual behavior
The conditional types do not produce the same output:
typex=Foo<"a"|"b",["a","b","b"]>// ["b", "b"]typey=Bar<"a"|"b",["a","b","b"]>// readonly ("a" | "b")[]typez=Baz<"a"|"b",["a","b","b"]>// ["b", "b"]🙂 Expected behavior
The conditional types should all produce the same output. The fact that K is a type parameter should not affect the output.
typex=Foo<"a"|"b",["a","b","b"]>// ["b", "b"]typey=Bar<"a"|"b",["a","b","b"]>// ["b", "b"]typez=Baz<"a"|"b",["a","b","b"]>// ["b", "b"]
Alternatively if that is infeasible for technical reasons, the conditional type should fail. Inferring the constraint makes traversing the tuple impossible.
Bug Report
🔎 Search Terms
conditional type, extends, infer, spread, tuple
🕗 Version & Regression Information
⏯ Playground Link
Playground link with relevant code
💻 Code
🙁 Actual behavior
The conditional types do not produce the same output:
🙂 Expected behavior
The conditional types should all produce the same output. The fact that
Kis a type parameter should not affect the output.Alternatively if that is infeasible for technical reasons, the conditional type should fail. Inferring the constraint makes traversing the tuple impossible.