-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: Conditional TypesThe issue relates to conditional typesThe issue relates to conditional typesFix AvailableA PR has been opened for this issueA PR has been opened for this issueRescheduledThis issue was previously scheduled to an earlier milestoneThis issue was previously scheduled to an earlier milestone
Milestone
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?
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: Conditional TypesThe issue relates to conditional typesThe issue relates to conditional typesFix AvailableA PR has been opened for this issueA PR has been opened for this issueRescheduledThis issue was previously scheduled to an earlier milestoneThis issue was previously scheduled to an earlier milestone