Skip to content
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

Reverse mapped type fails to be inferred with constraint that is a union containing an intersection #56910

Open
Andarist opened this issue Dec 31, 2023 · 0 comments · May be fixed by #56911
Open
Labels
Possible Improvement The current behavior isn't wrong, but it's possible to see that it might be better in some cases
Milestone

Comments

@Andarist
Copy link
Contributor

🔎 Search Terms

reverse mapped type inference inferred constraint union intersection

🕗 Version & Regression Information

⏯ Playground Link

https://www.typescriptlang.org/play?ts=5.4.0-dev.20231231#code/CYUwxgNghgTiAEAzArgOzAFwJYHtVNQB4AVeEADwxFWAGd4AlcHGYQ2jGLVAcwBp4qZAFsARiBgA+SQAocogFYAueAG8AUPHgBtANLxu8GQGsQATxyJ4pAGTwARFHsBKeAB8Ho+wF0VxPd4A3OoAvs5+wWB4HPDyCvAAvGqa8FAqACwATHwpoioAjAAMhTlaYCqcyCA5IZHRGPBwtMgQDUmIqHKKzsEA9L1aWgB6APzqQA

💻 Code

declare function fn<T extends Record<string, number>>(obj: {
  [K in (keyof T & "a") | "b"]: T[K];
}): T;
const obj = {
  a: 42,
  b: 100,
  c: true,
};
const result = fn(obj);

🙁 Actual behavior

It fails to infer T and uses its constraint

🙂 Expected behavior

It should infer { a: number; b: number; }

Additional information about the issue

No response

@RyanCavanaugh RyanCavanaugh added the Possible Improvement The current behavior isn't wrong, but it's possible to see that it might be better in some cases label Jan 4, 2024
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Jan 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Possible Improvement The current behavior isn't wrong, but it's possible to see that it might be better in some cases
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants