Skip to content

Remove redundant intersections #15

Description

@devanshj

One'd find many redudant intersections in the narrowed type, eg { a: number, b: string } & { a: number }, these should be removed.

Apart for the fact it would lead to better-looking types, it'd also preserve heuristics that typescript applies to types, for instance the following code would compile if we remove the redundant & { 0: number }. Although of course, it should have compiled with the redundant & { 0: number } too.

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

let x = {} as [number, string] | [string]
if (pa(x, p(".0 typeof ===", "number"))) {
  const [_, ...y] = x;
//                  ^? [number, string] & { 0: number }
  let test: [string] = y
//    ~~~~
// Type '(string | number)[]' is not assignable to type '[string]'
}

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions