🐛 Infer strict return from the handler map
The fallback overload could not infer `R` from the handlers: `R` appeared only inside the `Exact` constraint, which is not an inference site, so with inferred handler params it collapsed to `unknown` and the matcher silently returned `UnaryFn<T, unknown>`. Adding `Partial<Handlers<T, R>>` to the handler parameter gives `R` an inference site, so the common return is inferred from the handlers and the fallback alike. Tests drop their explicit handler return annotations: real handlers are short and unannotated, and the common type is now inferred from them.
This commit is contained in:
1 parent
2d3577716d
commit
c7223dbe69
2 files changed
+14
-14
No files matched your search
+1
-1
@@ -32,7 +32,7 @@ type Fallback<T extends string | number, Handled, R> = UnaryFn<
|
||||
interface MatcherStrict<T extends string | number> {
|
||||
<R>(handlers: Handlers<T, R>): UnaryFn<T, R>;
|
||||
<R, Handled extends Exact<Partial<Handlers<T, R>>, Handled>>(
|
||||
handlers: Handled,
|
||||
handlers: Handled & Partial<Handlers<T, R>>,
|
||||
fallback: Fallback<T, Handled, R>,
|
||||
): UnaryFn<T, R>;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user