♻️ Align primitive-union matcher names and drop stale lint disables
Rename `MatcherStrict` / `MatcherWidening` to `PrimitiveUnionMatcherStrict` / `PrimitiveUnionMatcherWidening`, matching the exported `getPrimitiveUnionMatcher(W)` names and the `TaggedUnionMatcher*` pair. Folds in the working-tree lint cleanups: drop the now-unneeded `typescript/unified-signatures` disables and turn the tagged-union factory interfaces into type aliases.
This commit is contained in:
1 parent
09e1c12270
commit
4ebe18adb1
2 files changed
+12
-14
No files matched your search
@@ -40,11 +40,10 @@ type MustBePartial<T extends Matchable, Handled> =
|
|||||||
// so `Exact` restores it for the generic forms: a handler map can otherwise
|
// so `Exact` restores it for the generic forms: a handler map can otherwise
|
||||||
// carry keys outside `T`.
|
// carry keys outside `T`.
|
||||||
|
|
||||||
// oxlint-disable typescript/unified-signatures
|
|
||||||
// Strict returns: one common `R`. Overload order is load-bearing:
|
// Strict returns: one common `R`. Overload order is load-bearing:
|
||||||
// #1 Handlers (first) -> the exhaustive form and the autocomplete popup
|
// #1 Handlers (first) -> the exhaustive form and the autocomplete popup
|
||||||
// #2 Fallback (last) -> accepts a partial handler map plus a fallback
|
// #2 Fallback (last) -> accepts a partial handler map plus a fallback
|
||||||
interface MatcherStrict<T extends Matchable> {
|
interface PrimitiveUnionMatcherStrict<T extends Matchable> {
|
||||||
<R>(handlers: Handlers<T, R>): UnaryFn<T, R>;
|
<R>(handlers: Handlers<T, R>): UnaryFn<T, R>;
|
||||||
<
|
<
|
||||||
R,
|
R,
|
||||||
@@ -55,13 +54,11 @@ interface MatcherStrict<T extends Matchable> {
|
|||||||
fallback: Fallback<T, Handled, R>,
|
fallback: Fallback<T, Handled, R>,
|
||||||
): UnaryFn<T, R>;
|
): UnaryFn<T, R>;
|
||||||
}
|
}
|
||||||
// oxlint-enable typescript/unified-signatures
|
|
||||||
|
|
||||||
// Widened returns: the union of every handler's return type. `P` is inferred
|
// Widened returns: the union of every handler's return type. `P` is inferred
|
||||||
// from the whole handler map, whose closed constraint supplies the
|
// from the whole handler map, whose closed constraint supplies the
|
||||||
// contextual/autocomplete type.
|
// contextual/autocomplete type.
|
||||||
// oxlint-disable typescript/unified-signatures
|
interface PrimitiveUnionMatcherWidening<T extends Matchable> {
|
||||||
interface MatcherWidening<T extends Matchable> {
|
|
||||||
<P extends Exact<Handlers<T, unknown>, P>>(
|
<P extends Exact<Handlers<T, unknown>, P>>(
|
||||||
handlers: P,
|
handlers: P,
|
||||||
): UnaryFn<T, PatternReturns<P>>;
|
): UnaryFn<T, PatternReturns<P>>;
|
||||||
@@ -74,7 +71,6 @@ interface MatcherWidening<T extends Matchable> {
|
|||||||
fallback: Fallback<T, Handled, R>,
|
fallback: Fallback<T, Handled, R>,
|
||||||
): UnaryFn<T, PatternReturns<Handled> | R>;
|
): UnaryFn<T, PatternReturns<Handled> | R>;
|
||||||
}
|
}
|
||||||
// oxlint-enable typescript/unified-signatures
|
|
||||||
|
|
||||||
const dispatch =
|
const dispatch =
|
||||||
(handlers: HandlerMap, fallback?: UnaryFn<never, unknown>) =>
|
(handlers: HandlerMap, fallback?: UnaryFn<never, unknown>) =>
|
||||||
@@ -101,7 +97,7 @@ const dispatch =
|
|||||||
|
|
||||||
export const getPrimitiveUnionMatcher = <
|
export const getPrimitiveUnionMatcher = <
|
||||||
T extends Matchable,
|
T extends Matchable,
|
||||||
>(): MatcherStrict<T> => dispatch;
|
>(): PrimitiveUnionMatcherStrict<T> => dispatch;
|
||||||
export const getPrimitiveUnionMatcherW = <
|
export const getPrimitiveUnionMatcherW = <
|
||||||
T extends Matchable,
|
T extends Matchable,
|
||||||
>(): MatcherWidening<T> => dispatch;
|
>(): PrimitiveUnionMatcherWidening<T> => dispatch;
|
||||||
+8
-6
@@ -102,13 +102,15 @@ interface TaggedUnionMatcherWidening<T extends object, K extends keyof T> {
|
|||||||
// The key-taking step of the curried factory. Naming it lets the factory return
|
// The key-taking step of the curried factory. Naming it lets the factory return
|
||||||
// `dispatch` directly, the tacit twin of the primitive-union factory's bare
|
// `dispatch` directly, the tacit twin of the primitive-union factory's bare
|
||||||
// `=> dispatch`.
|
// `=> dispatch`.
|
||||||
interface TaggedUnionMatcherFactory<T extends object> {
|
type TaggedUnionMatcherFactory<T extends object> = <K extends Discriminated<T>>(
|
||||||
<K extends Discriminated<T>>(k: K): TaggedUnionMatcherStrict<T, K>;
|
k: K,
|
||||||
}
|
) => TaggedUnionMatcherStrict<T, K>;
|
||||||
|
|
||||||
interface TaggedUnionMatcherWideningFactory<T extends object> {
|
type TaggedUnionMatcherWideningFactory<T extends object> = <
|
||||||
<K extends Discriminated<T>>(k: K): TaggedUnionMatcherWidening<T, K>;
|
K extends Discriminated<T>,
|
||||||
}
|
>(
|
||||||
|
k: K,
|
||||||
|
) => TaggedUnionMatcherWidening<T, K>;
|
||||||
|
|
||||||
const dispatch =
|
const dispatch =
|
||||||
(k: PropertyKey) =>
|
(k: PropertyKey) =>
|
||||||
|
|||||||
Reference in new issue
Block a user