diff --git a/src/common/ipc/update-available.ipc.ts b/src/common/ipc/update-available.ipc.ts index 28bdb3f8c2..29258455d0 100644 --- a/src/common/ipc/update-available.ipc.ts +++ b/src/common/ipc/update-available.ipc.ts @@ -32,8 +32,8 @@ function isUpdateInfo(src: unknown): src is UpdateInfo { && hasTypedProperty(src, "releaseDate", isString) && hasTypedProperty(src, "files", bindPredicate(isTypedArray, isUpdateFileInfo)) && hasOptionalProperty(src, "releaseName", bindPredicateOr(isString, isNull)) - && hasOptionalProperty(src, "stagingPercentage", isNumber) - && hasOptionalProperty(src, "releaseNotes", bindPredicateOr(isString, isReleaseNoteInfo, isNull)); + && hasOptionalProperty(src, "releaseNotes", bindPredicateOr(isString, isReleaseNoteInfo, isNull)) + && hasOptionalProperty(src, "stagingPercentage", isNumber); } export function isUpdateAvailableArgs(args: unknown[]): args is UpdateAvailableArgs { diff --git a/src/common/utils/type-narrowing.ts b/src/common/utils/type-narrowing.ts index f92202f3cb..d4a6700d98 100644 --- a/src/common/utils/type-narrowing.ts +++ b/src/common/utils/type-narrowing.ts @@ -113,20 +113,13 @@ export function bindPredicate(fn: (arg1: unknown, ...ar } type Predicate = (arg: unknown) => arg is T; +type Rest = T extends [any, ...infer R] ? R : any; +type First = T extends [infer R, ...any[]] ? R : any; +type ReturnPredicateType src is any> = T extends (src: unknown) => src is infer R ? R : any; +type OrReturnPredicateType[]> = ReturnPredicateType> | (T extends [any] ? never : OrReturnPredicateType>); -export function bindPredicateOr(p1: Predicate): Predicate; -export function bindPredicateOr(p1: Predicate, p2: Predicate): Predicate; -export function bindPredicateOr(p1: Predicate, p2: Predicate, p3: Predicate): Predicate; -export function bindPredicateOr(p1: Predicate, p2: Predicate, p3: Predicate, p4: Predicate): Predicate; - -export function bindPredicateOr(...predicates: T): Predicate { - return (arg: unknown): arg is any => { - for (const predicate of predicates) { - if (predicate) { - return true; - } - } - - return false; +export function bindPredicateOr[]>(...predicates: Predicates): Predicate> { + return (arg: unknown): arg is OrReturnPredicateType => { + return predicates.some(predicate => predicate(arg)); }; }