Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Wrong completions for discriminated unions with generic index #34752

Copy link
Copy link
@asvetliakov

Description

@asvetliakov
Issue body actions

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

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.