Skip to content

Extract of union doesn't work with in operator #60115

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
FrankiePo opened this issue Oct 2, 2024 · 2 comments
Closed

Extract of union doesn't work with in operator #60115

FrankiePo opened this issue Oct 2, 2024 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@FrankiePo
Copy link

FrankiePo commented Oct 2, 2024

πŸ”Ž Search Terms

extract union in operator

πŸ•— Version & Regression Information

  • I tested this on 5.6.2

⏯ Playground Link

https://www.typescriptlang.org/play/?ssl=12&ssc=7&pln=12&pc=71#code/C4TwDgpgBAggNnKBeKByAhqqAfNAjLXVAY1QG4AoC0SWZNTSi4gewDsBnYKVtgMwCWAc3oBvClElR0ALigAKAJTIAfD3YcWcCADo4LIfIypFAGgoBfKB3TABHQRA5QAShFYAnACYAeGKYVlJDUANxYBLxUmXi5pBDl4RBQAWVsACx0PdDYvFgBbJSg1AAYdAFYoAH4GLDlUAiYBPgV0BCgBNnV+YWVxKSgAegGoAAUPFkgPUHwsXKcoNhZuCAAPe252KBpoVFFpOULgqDCIsigLVB15AHZisoBmRQkpXkEhAG1WuABdJUp+oZQVaQYjACBeORfdrObYsZrGSxAA

πŸ’» Code

type All = 'a' | 'b' | 'c';

type A = 'a';

const config = {
    a: () => console.log('a'),
} satisfies Record<A, () => void>;

const all: All = Math.random() > 0.5 ? 'a' : 'b';

if (all in config) {
    // Property 'b' does not exist on type '{ a: () => void; }'.(7053)
    config[all]();
    // expected: all is typeof 'a'
}

πŸ™ Actual behavior

Got an error: Property 'b' does not exist on type '{ a: () => void; }'.(7053)

πŸ™‚ Expected behavior

I expected to all be a type of 'a' after in operator. Like guard will do:

function guard(a: All): a is A {
    return a in config;
}

Additional information about the issue

No response

@jcalz
Copy link
Contributor

jcalz commented Oct 2, 2024

#43284 duplicate

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Oct 2, 2024
@typescript-bot
Copy link
Collaborator

This issue has been marked as "Duplicate" and has seen no recent activity. It has been automatically closed for house-keeping purposes.

@typescript-bot typescript-bot closed this as not planned Won't fix, can't repro, duplicate, stale Oct 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants