You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// some generic type with 2 type parameterstypeF<I,O>={__type: (input: I)=>O}// this is what I wantdeclarefunctionjoin<I,OSextendsunknown[]>(...fs: {[KinkeyofOS]: F<I,OS[K]>}): F<I,OS>declareconstf1: F<number,string>declareconstf2: F<number,boolean>// (1)// expected: join<number, [string, boolean, string]>join(f1,f2,f1)// actual: join<unknown, [string, boolean, string]>, I type is inferred as unknown// ~~ Argument of type 'F<number, string>' is not assignable to parameter of type 'F<unknown, string>'.// let's try with fixed tupledeclarefunctionjoin2<I,OSextendsreadonly[unknown,unknown,unknown]>(...fs: [F<I,OS[0]>,F<I,OS[1]>,F<I,OS[2]>]): F<I,OS>// (2)// expected: join2<number, [string, boolean, string]>join2(f1,f2,f1)// actual: join2<number, [unknown, unknown, unknown]>, I inferred correctly, but OS isn't// not what I need, but let's try with only inferring from mapped typedeclarefunctionjoin3<OSextendsunknown[]>(...fs: {[KinkeyofOS]: F<number,OS[K]>}): F<number,OS>// expected: join3<[string, boolean, string]>join3(f1,f2,f1)// actual, as expected: join3<[string, boolean, string]>
🙁 Actual behavior
(1) call to be inferred as join<unknown, [string, boolean, string]>, could not infer I
(2) call to be inferred as join2<number, [unknown, unknown, unknown]>, could not infer OS
🙂 Expected behavior
(1) call to be inferred as join<number, [string, boolean, string]>
(2) call to be inferred as join2<number, [string, boolean, string]>
The text was updated successfully, but these errors were encountered:
In general I don't think the sort of inference to { [K in keyof OS]: F<I, OS[K]> } is possible with our current machinery; it's almost circular by definition and would require a lot of rethinking.
I see, it can be worked around. I actually was able to come up with the same solution. However, I thought it might be worth to point out these inconsistencies and limitations. The original typing of the function seems much more reasonable and surprisingly not working. I take a look at the referenced issues if they are really the same. But I'd say this repro is quite understand anyway.
Bug Report
🔎 Search Terms
🕗 Version & Regression Information
⏯ Playground Link
Playground link with relevant code
💻 Code
🙁 Actual behavior
join<unknown, [string, boolean, string]>
, could not inferI
join2<number, [unknown, unknown, unknown]>
, could not inferOS
🙂 Expected behavior
join<number, [string, boolean, string]>
join2<number, [string, boolean, string]>
The text was updated successfully, but these errors were encountered: