Open jb-asi opened 3 weeks ago
To give a little more context why this may have to do with the union, this simple example does fail the .exhaustive
check with a NonExhaustiveError
-type error.
type A = {
key?: undefined;
};
const a: A = {};
match(a)
.with({ key: undefined }, () => void undefined)
.exhaustive();
Describe the bug Do we see any issue with the first match below, or no? Another reported issue followed up with
.otherwise
; but - in my case - we use.exhaustive
and end up throwing this error at runtime:Curiously, though, there is no compile-time type error as you'd usually expect to be coming from
.exhaustive
.Thinking this may be caused by using a tagged union type with a partial tag (meaning one of the unioned types has an optional tagging property). The
match..with..exhaustive
expression seems to be fine with{ type: undefined }
but then throws at runtime. Only when swapping to{ type: P.optional(undefined) }
does the runtime error subside; but the main issue is that.exhaustive
does not seem to be checking for this edge case.As another data point, if we change the types like so:
There is an
.exhaustive
error in that case.Really appreciate this library. If this seems simple enough for a public contributor to assist with in some capacity, let me know.
Versions