Closed
Description
TypeScript Version: 2.9.2
Search Terms:
conditional type constraint
Code
declare class Model<M extends MR, MR extends {}> {
// Compiler error:
// Type 'M[K]' does not satisfy the constraint 'K extends keyof MR ? MR[K] : M[K]'.
public getField2<K extends keyof M>(): Field<M[K], K extends keyof MR ? MR[K] : M[K]>
}
declare class Field<T extends TR, TR> {
}
Expected behavior:
No compiler error.
Because M extends MR
, and K extends keyof M
:
- If
K extends keyof MR
, then I expectM[K]
to satisfy the constraintMR[K]
. - Else, I expect
M[K]
to satisfy the constraintM[K]
. - Therefore, it seems that
M[K]
should satisfy the constraintK extends keyof MR ? MR[K] : M[K]
Actual behavior:
Compiler error: Type 'M[K]' does not satisfy the constraint 'K extends keyof MR ? MR[K] : M[K]'.
Related Issues:
Possibly?