TypeScript 引数にも返り値にも現れない関数のジェネリクスを推論することはできない
#TypeScript
タイトルそのままです
ジェネリクスを推論することができないだけでなく、引数と返り値が同じでジェネリクスだけ異なる関数シグネチャを区別することもできないようです
「ジェネリクスである関数シグネチャ」と「ジェネリクスのない関数シグネチャ」の区別すらもできないです
code:.ts
function test<X>() { }
function test2() { }
type A = (() => void) extends (<_>() => void) ? true : false
type B = typeof test
type C = typeof test<never>
type D = B extends C ? true : false
type checker<X> = X extends <_>() => void ? true : false
type E = checker<B>
type F = checker<C>
type G = checker<typeof test>
type checker2<X extends <_>() => void> = (f: X) => typeof f<any>
type H = checker2<typeof test>
type I = checker2<typeof test2>
type checker3<K, X extends <K>() => void> = (f: X) => typeof f<K>
type J = checker3<any, typeof test>
type K = checker3<any, typeof test2>
type checker4<K, X extends <_>() => void> = (f: X, g: typeof f<K>) => typeof f<K>
type L = checker4<any, typeof test>
type M = checker4<any, typeof test2>
type checker5<K, X extends <_>() => void> = (f: X, g: typeof f<K>) => typeof g extends typeof f<infer T> ? T : never;
type N = checker5<any, typeof test>
type O = checker5<any, typeof test2>
function test3<N extends "1" | "2">(n: N): N { return n }
type checker6<K, X extends <_>(...args: any[]) => any> = (f: X, g: typeof f<K>) => typeof g extends typeof f<infer T> ? T : never;
type P = checker6<any, typeof test3>
type Q = checker6<"1", typeof test3>
type R = typeof test3<"1"> extends typeof test3<"2"> ? true : false
function test4<N extends "1" | "2">(n: N): void {}
type S = typeof test4<"1"> extends typeof test4<"2"> ? true : false
function test5<N extends "1" | "2">(): void { }
type T = typeof test5<"1"> extends typeof test5<"2"> ? true : false
type U = typeof test5<"1"> extends typeof test5<infer a extends "1" | "2"> ? a : false
type V = typeof test5<"1"> extends typeof test5<infer a extends "2"> ? a : false