Minimal code to reproduce the problem ts
type X = "A" | "B";
const f = (x: X): X => (x);
const a: "A" = f("A"); // error
error
- Type βXβ is not assignable to type ββAββ.
- Type ββBββ is not assignable to type ββAββ
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.