-
Notifications
You must be signed in to change notification settings - Fork 12.8k
in
Operator Narrowing is Too Limited
#50891
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
Comments
This is basically a duplicate of #42384 (which in turn is a duplicate of a much older issue for the same scenario, but I can't locate that right now). You'd see the same problem if you started out with a EDIT: The oldest related issue I can locate right now is #29827, but no doubt there are more. |
It's interesting, though... We could consider having a type Point = { x: number, y: number };
declare function doWithPoint(p: Point): void;
function test(p: Partial<Point>) {
if (p.x && p.y) {
doWithPoint(p); // Narrowed to Partial<Point> & Record<"x", number> & Record<"y", number>
}
} One concern would be the noise created by all the intersections, but it does seem like a workable idea. |
This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
Playground Link
Expected: No errors
Actual Errors.
The text was updated successfully, but these errors were encountered: