ts-pattern
Advanced tools
Comparing version 5.1.0 to 5.1.1-rc.0
import type { Override } from './Pattern.js'; | ||
import type { BuiltInObjects, Compute, ExcludeObjectIfContainsNever, IsPlainObject, IsReadonlyArray, LeastUpperBound, MaybeAddReadonly, ValueOf } from './helpers.js'; | ||
export type ExtractPreciseValue<a, b> = b extends Override<infer b1> ? b1 : unknown extends b ? a : 0 extends 1 & b ? a : 0 extends 1 & a ? b : b extends readonly any[] ? ExtractPreciseArrayValue<a, b, IsReadonlyArray<a>> : b extends Map<infer bk, infer bv> ? a extends Map<infer ak, infer av> ? Map<ExtractPreciseValue<ak, bk>, ExtractPreciseValue<av, bv>> : LeastUpperBound<a, b> : b extends Set<infer bv> ? a extends Set<infer av> ? Set<ExtractPreciseValue<av, bv>> : LeastUpperBound<a, b> : IsPlainObject<b, BuiltInObjects | Error> extends true ? a extends object ? a extends b ? a : b extends a ? [Exclude<keyof a, keyof b>] extends [never] ? b : Compute<ExcludeObjectIfContainsNever<b> & Omit<a, keyof b>> : [keyof a & keyof b] extends [never] ? never : ExcludeObjectIfContainsNever<Compute<{ | ||
[k in Exclude<keyof a, keyof b>]: a[k]; | ||
import type { BuiltInObjects, Compute, Contains, IsPlainObject, IsReadonlyArray, LeastUpperBound, MaybeAddReadonly, ValueOf } from './helpers.js'; | ||
export type ExtractPreciseValue<a, b> = b extends Override<infer b1> ? b1 : unknown extends b ? a : 0 extends 1 & b ? a : 0 extends 1 & a ? b : b extends readonly any[] ? ExtractPreciseArrayValue<a, b, IsReadonlyArray<a>> : b extends Map<infer bk, infer bv> ? a extends Map<infer ak, infer av> ? Map<ExtractPreciseValue<ak, bk>, ExtractPreciseValue<av, bv>> : LeastUpperBound<a, b> : b extends Set<infer bv> ? a extends Set<infer av> ? Set<ExtractPreciseValue<av, bv>> : LeastUpperBound<a, b> : IsPlainObject<b, BuiltInObjects | Error> extends true ? a extends object ? a extends b ? a : b extends a ? Contains<b, never> extends true ? never : Contains<Omit<b, keyof a>, {}> extends true ? never : [ | ||
Exclude<keyof a, keyof b> | ||
] extends [never] ? b : Compute<b & Omit<a, keyof b>> : [keyof a & keyof b] extends [never] ? never : Compute<{ | ||
[k in keyof a as k extends keyof b ? never : k]: a[k]; | ||
} & { | ||
[k in keyof b]: k extends keyof a ? ExtractPreciseValue<a[k], b[k]> : b[k]; | ||
}>, keyof b & string> : LeastUpperBound<a, b> : LeastUpperBound<a, b>; | ||
}> extends infer result ? Contains<Pick<result, keyof result & keyof b>, never> extends true ? never : result : never : LeastUpperBound<a, b> : LeastUpperBound<a, b>; | ||
type ExtractPreciseArrayValue<a, b, isReadonly extends boolean, startOutput extends any[] = [], endOutput extends any[] = []> = a extends readonly (infer aItem)[] ? b extends readonly [] ? MaybeAddReadonly<[...startOutput, ...endOutput], isReadonly> : b extends readonly [infer b1, ...infer bRest] ? a extends readonly [infer a1, ...infer aRest] ? ExtractPreciseValue<a1, b1> extends infer currentValue ? [currentValue] extends [never] ? never : ExtractPreciseArrayValue<aRest, bRest, isReadonly, [ | ||
@@ -9,0 +11,0 @@ ...startOutput, |
@@ -12,10 +12,5 @@ export type ValueOf<a> = a extends readonly any[] ? a[number] : a[keyof a]; | ||
export type LeastUpperBound<a, b> = b extends a ? b : a extends b ? a : never; | ||
/** | ||
* if a key of an object has the never type, | ||
* returns never, otherwise returns the type of object | ||
**/ | ||
export type ExcludeIfContainsNever<a, b> = b extends Map<any, any> | Set<any> ? a : b extends readonly [any, ...any] ? ExcludeObjectIfContainsNever<a, keyof b & ('0' | '1' | '2' | '3' | '4')> : b extends readonly any[] ? ExcludeObjectIfContainsNever<a, keyof b & number> : ExcludeObjectIfContainsNever<a, keyof b & string>; | ||
export type ExcludeObjectIfContainsNever<a, keyConstraint = unknown> = a extends any ? 'exclude' extends { | ||
[k in keyConstraint & keyof a]-?: [a[k]] extends [never] ? 'exclude' : 'include'; | ||
}[keyConstraint & keyof a] ? never : a : never; | ||
export type Contains<a, b> = a extends any ? 'exclude' extends { | ||
[k in keyof a]-?: Equal<a[k], b> extends true ? 'exclude' : 'include'; | ||
}[keyof a] ? true : false : never; | ||
export type UnionToIntersection<union> = (union extends any ? (k: union) => void : never) extends (k: infer intersection) => void ? intersection : never; | ||
@@ -22,0 +17,0 @@ export type IsUnion<a> = [a] extends [UnionToIntersection<a>] ? false : true; |
{ | ||
"name": "ts-pattern", | ||
"version": "5.1.0", | ||
"version": "5.1.1-rc.0", | ||
"description": " The exhaustive Pattern Matching library for TypeScript.", | ||
@@ -5,0 +5,0 @@ "type": "module", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
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
407515
1450
1