effect icon indicating copy to clipboard operation
effect copied to clipboard

Incorrect type inference on Match.type<Array>

Open HugeLetters opened this issue 7 months ago • 0 comments

What version of Effect is running?

3.15.2

What steps can reproduce the bug?

https://effect.website/play/#18a138640989

Match.type<Array-ish>() with Match.when([...stuff]) works fine with tuples but inference kinda fails with arrays.

type Item=string | number | null;
const match = Match.type<Array<Item>>().pipe(
	Match.when(["A", Match.null], (a) => a),
        //                             ^? same issue here
	Match.orElseAbsurd,
);


const a = match(["A", null, 'b', 1])
//    ^? ReadonlyArray<"A" | null>
// should be ["A", null, ...Array<Item>]

What is the expected behavior?

  1. I wanna see that first 2 elements are "A" and null - not an error but renders matching kinda useless
  2. rest of the elements can be of any types actually, not just "A" | null - this is an error

What do you see instead?

No response

Additional information

I have a suggested solution described here - the proposed solution is line 93 https://effect.website/play/#ef4051fe0011

I can issue a PR

HugeLetters avatar May 18 '25 14:05 HugeLetters