Skip to content

Wrong completions for discriminated unions with generic index #34752

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
asvetliakov opened this issue Oct 26, 2019 · 2 comments
Closed

Wrong completions for discriminated unions with generic index #34752

asvetliakov opened this issue Oct 26, 2019 · 2 comments
Labels
Bug A bug in TypeScript Domain: Completion Lists The issue relates to showing completion lists in an editor
Milestone

Comments

@asvetliakov
Copy link

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

@asvetliakov asvetliakov changed the title Wrong completions for discriminated unions Wrong completions for discriminated unions with generic index Oct 26, 2019
@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Oct 30, 2019
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Oct 30, 2019
@RyanCavanaugh RyanCavanaugh added the Domain: Completion Lists The issue relates to showing completion lists in an editor label Oct 30, 2019
@Andarist
Copy link
Contributor

This was some temporary regression - it worked fine in 3.6, but was broken in 3.7 and fixed in 3.8. I think that the issue can be closed, cc @RyanCavanaugh

@jakebailey
Copy link
Member

This was broken by #33937 then fixed in #36556, so this issue was an early catch of #35702.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Domain: Completion Lists The issue relates to showing completion lists in an editor
Projects
None yet
Development

No branches or pull requests

4 participants