Here is some code to analyze:
type T = 'a' | "b"
type M = {
a: 1,
b: 2
}
function a(a: 'a') {}
function m1(a: 1) {}
function f<TT extends T>(t: TT, p: M[TT]) {
switch (t) {
case "a": {
a(t)
m1(p) // Argument of type '1 | 2' is not assignable to parameter of type '1'
break
}
}
}
What is the reason why p
didn't narrow down to 1
? Is there a clever solution without resorting to type casts?