Closed
Description
TypeScript Version: 3.7.2
Search Terms: ts2345 derivated type error
I really don't know how to describe this bug in short terms.
Code
enum A {
a = 'a',
b = 'b'
}
interface ObjA {
prop1: string;
}
interface ObjB {
prop2: number;
}
type PayloadMap = {
[A.a]: ObjA;
[A.b]: ObjB;
}
type Content<T extends A> = {
type: T;
payload: PayloadMap[T];
}
function processContent<T extends A>(content: Content<T>) {
parserPayload[content.type](content.payload);
// ^=========== here is the error
}
const parserPayload: { [key in A]: (payload: PayloadMap[key]) => any } = {
// ^============ because this is treated
// as an intersection
a: payload => payload.prop1,
b: payload => payload.prop2,
}
Expected behavior: To correctly know that PayloadMap[key]
is in fact the same as PayloadMap[T]
since key
matches T
.
Actual behavior:
Argument of type 'PayloadMap[T]' is not assignable to parameter of type 'ObjA & ObjB'.
Related Issues: