-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Labels
Description
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]'
}