Skip to content

Assignability issue in narrowed constrained key type  #12635

Closed
@tinganho

Description

@tinganho

The below code:

class M {
    __m: any;
}
class C {
    __c: any;
}
type D = typeof M | typeof C;
interface R {
    [i: string]: D;
}
function f1(p: D) {
}
interface P {
    p1: string;
    p2: string;
}
function f2<K extends keyof P>(p: K) {
    let r: R = {};
    if (p in r) {
        f1(r[p]); // Error  `R[K]` is not assignable to `D`
    }
}

Gives me the error R[K] is not assignable to D.

Though isn't R[K] equal to D?

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions