Minimal code to reproduce the problem ts
type X = "A" | "B";
const f = (x: X): X => (x);
const a: "A" = f("A"); // error
error
solution ts
const f = <T extends X>(x: T): T => (x);
const a: "A" = f("A"); // ok
This page is auto-translated from /nishio/ジェネリクスが必要な例 using DeepL. If you looks something interesting but the auto-translated English is not good enough to understand it, feel free to let me know at @nishio_en. I'm very happy to spread my thought to non-Japanese readers.