ts-pattern
Advanced tools
Comparing version 0.2.1 to 0.2.2
import { PatternType, __ } from './Pattern'; | ||
import { ExcludeIfContainsNever, LeastUpperBound } from './helpers'; | ||
export declare type ExtractPreciseValue<a, b> = b extends [] ? [] : [a, b] extends [[infer a1, infer a2, infer a3, infer a4, infer a5] | infer otherBranches, [infer b1, infer b2, infer b3, infer b4, infer b5]] ? [ExtractPreciseValue<a1, b1>, ExtractPreciseValue<a2, b2>, ExtractPreciseValue<a3, b3>, ExtractPreciseValue<a4, b4>, ExtractPreciseValue<a5, b5>] : [a, b] extends [[infer a1, infer a2, infer a3, infer a4] | infer otherBranches, [infer b1, infer b2, infer b3, infer b4]] ? [ExtractPreciseValue<a1, b1>, ExtractPreciseValue<a2, b2>, ExtractPreciseValue<a3, b3>, ExtractPreciseValue<a4, b4>] : [a, b] extends [[infer a1, infer a2, infer a3] | infer otherBranches, [infer b1, infer b2, infer b3]] ? [ExtractPreciseValue<a1, b1>, ExtractPreciseValue<a2, b2>, ExtractPreciseValue<a3, b3>] : [a, b] extends [[infer a1, infer a2] | infer otherBranches, [infer b1, infer b2]] ? [ExtractPreciseValue<a1, b1>, ExtractPreciseValue<a2, b2>] : [a, b] extends [(infer a1)[], (infer b1)[]] ? ExtractPreciseValue<a1, b1>[] : [a, b] extends [Map<infer ak, infer av>, Map<infer bk, infer bv>] ? Map<ExtractPreciseValue<ak, bk>, ExtractPreciseValue<av, bv>> : [a, b] extends [Set<infer av>, Set<infer bv>] ? Set<ExtractPreciseValue<av, bv>> : b extends typeof __ ? a : b extends { | ||
export declare type ExtractPreciseValue<a, b> = ExcludeIfContainsNever<b extends [] ? [] : b extends typeof __ ? a : b extends { | ||
valueKind: PatternType.Not; | ||
value: infer b1; | ||
} ? Exclude<a, b1> : b extends object ? b extends a ? b : a extends b ? a : ExcludeIfContainsNever<{ | ||
} ? Exclude<a, b1> : [a, b] extends [([infer a1, infer a2, infer a3, infer a4, infer a5] | infer otherBranches), [infer b1, infer b2, infer b3, infer b4, infer b5]] ? [ExtractPreciseValue<a1, b1>, ExtractPreciseValue<a2, b2>, ExtractPreciseValue<a3, b3>, ExtractPreciseValue<a4, b4>, ExtractPreciseValue<a5, b5>] : [a, b] extends [[infer a1, infer a2, infer a3, infer a4] | infer otherBranches, [infer b1, infer b2, infer b3, infer b4]] ? [ExtractPreciseValue<a1, b1>, ExtractPreciseValue<a2, b2>, ExtractPreciseValue<a3, b3>, ExtractPreciseValue<a4, b4>] : [a, b] extends [[infer a1, infer a2, infer a3] | infer otherBranches, [infer b1, infer b2, infer b3]] ? [ExtractPreciseValue<a1, b1>, ExtractPreciseValue<a2, b2>, ExtractPreciseValue<a3, b3>] : [a, b] extends [[infer a1, infer a2] | infer otherBranches, [infer b1, infer b2]] ? [ExtractPreciseValue<a1, b1>, ExtractPreciseValue<a2, b2>] : [a, b] extends [(infer a1)[], (infer b1)[]] ? ExtractPreciseValue<a1, b1>[] : [a, b] extends [Map<infer ak, infer av>, Map<infer bk, infer bv>] ? Map<ExtractPreciseValue<ak, bk>, ExtractPreciseValue<av, bv>> : [a, b] extends [Set<infer av>, Set<infer bv>] ? Set<ExtractPreciseValue<av, bv>> : b extends object ? a extends object ? b extends a ? b : a extends b ? a : { | ||
[k in keyof Required<a>]: k extends keyof b ? ExtractPreciseValue<a[k], b[k]> : a[k]; | ||
}> : LeastUpperBound<a, b>; | ||
} : never : LeastUpperBound<a, b>>; |
@@ -15,5 +15,5 @@ export declare type ValueOf<a> = a[keyof a]; | ||
**/ | ||
export declare type ExcludeIfContainsNever<a> = ValueOf<{ | ||
export declare type ExcludeIfContainsNever<a> = a extends any[] | Map<any, any> | Set<any> ? a : a extends object ? { | ||
[k in keyof a]-?: a[k] extends never ? 'exclude' : 'include'; | ||
}> extends 'include' ? a : never; | ||
}[keyof a] extends 'include' ? a : never : a; | ||
export declare type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never; |
@@ -38,3 +38,2 @@ import { Pattern, SelectPattern, GuardValue } from './Pattern'; | ||
export declare type ExtractSelections<a, p extends Pattern<a>> = UnionToIntersection<FindSelected<MatchedValue<a, p>, p>>; | ||
export declare type PatternHandler<a, p extends Pattern<a>, c> = (value: MatchedValue<a, p>, selections: ExtractSelections<a, p>) => c; | ||
export declare type Unset = '@match/unset'; | ||
@@ -52,3 +51,3 @@ export declare type PickReturnValue<a, b> = a extends Unset ? b : a; | ||
**/ | ||
with<p extends Pattern<a>, c>(pattern: p, handler: PatternHandler<a, p, PickReturnValue<b, c>>): Match<a, PickReturnValue<b, c>>; | ||
with<p extends Pattern<a>, c>(pattern: p, handler: (value: MatchedValue<a, p>, selections: ExtractSelections<a, p>) => PickReturnValue<b, c>): Match<a, PickReturnValue<b, c>>; | ||
with<pat extends Pattern<a>, pred extends (value: MatchedValue<a, pat>) => unknown, c>(pattern: pat, predicate: pred, handler: (value: GuardValue<pred>, selections: ExtractSelections<a, pat>) => PickReturnValue<b, c>): Match<a, PickReturnValue<b, c>>; | ||
@@ -55,0 +54,0 @@ with<pat extends Pattern<a>, pred extends (value: MatchedValue<a, pat>) => unknown, pred2 extends (value: GuardValue<pred>) => unknown, c>(pattern: pat, predicate: pred, predicate2: pred2, handler: (value: GuardValue<pred2>, selections: ExtractSelections<a, pat>) => PickReturnValue<b, c>): Match<a, PickReturnValue<b, c>>; |
{ | ||
"name": "ts-pattern", | ||
"version": "0.2.1", | ||
"version": "0.2.2", | ||
"description": "Typescript pattern matching library", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
24226
0
435