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

make { a: string, b: number } & { a: number } resolve to never #11

Closed
devanshj opened this issue Oct 10, 2022 · 1 comment
Closed

make { a: string, b: number } & { a: number } resolve to never #11

devanshj opened this issue Oct 10, 2022 · 1 comment

Comments

@devanshj
Copy link
Owner

This should compile... Or at least find a good reason why it should not :P

import { p, pa } from "@sthir/predicate"

let x = {} as { a: number; b: string } | { a: string; b: number }
if (pa(x, p(".a typeof ===", "number"))) {
  let test: string = x.b    
  //  ~~~~
  // Type 'string | number' is not assignable to type 'string'.
}
@devanshj devanshj changed the title predicate: make { a: string, b: number } & { a: number } resolve to never make { a: string, b: number } & { a: number } resolve to never Oct 10, 2022
@devanshj
Copy link
Owner Author

devanshj commented Oct 10, 2022

Previously we'd normalize an object to never only if all values were never, but now we do that if we find any value that is never, which is theoretically correct, so I hope there wouldn't be any regressions :P

Although some people use never as "not allowed" as in { a: string, b?: never }, so if they have objects like this in the tree they'd just disappear. In order to prevent this we could only check for never produced by intersections, ie normalizing { a: string, b: number } & { a: number } to never is fine, but normalizing { a: never, b: number } to never is not ideal.

Opened #16.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant