Skip to content

Wrong completions for discriminated unions with generic index #34752

Closed
@asvetliakov

Description

@asvetliakov

TypeScript Version: 3.8.0-dev.20191026

Search Terms:
completions, discriminated unions

Code

const A = "A";
const B = "B";

interface AAction {
    type: typeof A;
    payload: {
        a: string;
        b: string;
    }
}

interface BAction {
    type: typeof B;
    payload: {
        c: string;
        d: string;
    }
}
interface ActionMap {
    [A]: AAction;
    [B]: BAction;
}

declare function test<K extends keyof ActionMap>(key: K, payload: ActionMap[K]["payload"]): void;
test("A", { /* completion here */ })

Expected behavior:
Should give only a and b . TS 3.6.3 (haven't tested on 3.6.4) works fine

Actual behavior:
Returns a, b, c, d

Playground Link: http://www.typescriptlang.org/play/?ts=3.8.0-dev.20191025#code/FAYw9gdgzgLgBAQTgXjgIgWg3KSs4BCK6B2wwAlhDAKYBOAZgIYg2IIgwWRwDewcQXBgBPAA40AXMPE0wDRDiFwxTEQBswTACbT+y5U2mw6VAOZKDggEbGYpiBYFCAvsDeVq9Zq0IcuPPpCohLSIXIKBJaCqhpaunzOViB2Dk5Wggkm5tFwbm5UtIwsbP7cEACyTGKJygDaCAC60ghlkLl1BM1+nOU4Hto0IOpMdGwMAK4QvTy0sAA8ANJwNAAetBDaUHAA1jQi8ogzldUAfAAUeyLSiwA0KmqaOi3HVWJ1i411aLFP2miNACU0gAbmAKNocHMYOcMGh7rxBC5AUA

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptDomain: Completion ListsThe issue relates to showing completion lists in an editor

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions