From f7a3dc9b8e9de3c3dbdbd4baca17e0a1dbc537e3 Mon Sep 17 00:00:00 2001 From: Michael Gunter Date: Tue, 17 Oct 2023 18:49:58 -0700 Subject: [PATCH] add overrides for type guard predicates --- linq.d.ts | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/linq.d.ts b/linq.d.ts index c2daa60..9fff437 100644 --- a/linq.d.ts +++ b/linq.d.ts @@ -56,6 +56,7 @@ declare namespace Enumerable { selectMany(collectionSelector: (element: T, index: number) => TCollection[], resultSelector: (outer: T, inner: TCollection) => TResult): IEnumerable; selectMany(collectionSelector: (element: T, index: number) => { length: number;[x: number]: TOther; }): IEnumerable; selectMany(collectionSelector: (element: T, index: number) => { length: number;[x: number]: TCollection; }, resultSelector: (outer: T, inner: TCollection) => TResult): IEnumerable; + where(predicate: (element: T, index: number) => element is TOther): IEnumerable; where(predicate: (element: T, index: number) => boolean): IEnumerable; choose(selector: (element: T, index: number) => T): IEnumerable; ofType(type: unknown): IEnumerable; @@ -142,14 +143,30 @@ declare namespace Enumerable { sum(selector?: (element: T) => number): number; elementAt(index: number): T; elementAtOrDefault(index: number, defaultValue?: T): T | undefined; + first(predicate: (element: T, index: number) => element is TOther): TOther; first(predicate?: (element: T, index: number) => boolean): T; - firstOrDefault(predicate?: (element: T, index: number) => boolean, defaultValue?: T): T | undefined; - firstOrDefault(defaultValue?: T): T | undefined; + firstOrDefault(predicate: (element: T, index: number) => element is TOther, defaultValue: TDefault): TOther | TDefault; + firstOrDefault(predicate: (element: T, index: number) => boolean, defaultValue: TDefault): T | TDefault; + firstOrDefault(predicate: (element: T, index: number) => element is TOther): TOther | undefined; + firstOrDefault(predicate: (element: T, index: number) => boolean): T | undefined; + firstOrDefault(defaultValue: TDefault): T | TDefault; + firstOrDefault(): T | undefined; + last(predicate: (element: T, index: number) => element is TOther): TOther; last(predicate?: (element: T, index: number) => boolean): T; - lastOrDefault(predicate?: (element: T, index: number) => boolean, defaultValue?: T): T | undefined; - lastOrDefault(defaultValue?: T): T | undefined; + lastOrDefault(predicate: (element: T, index: number) => element is TOther, defaultValue: TDefault): TOther | TDefault; + lastOrDefault(predicate: (element: T, index: number) => boolean, defaultValue: TDefault): T | TDefault; + lastOrDefault(predicate: (element: T, index: number) => element is TOther): TOther | undefined; + lastOrDefault(predicate: (element: T, index: number) => boolean): T | undefined; + lastOrDefault(defaultValue: TDefault): T | TDefault; + lastOrDefault(): T | undefined; + single(predicate: (element: T, index: number) => element is TOther): TOther; single(predicate?: (element: T, index: number) => boolean): T; - singleOrDefault(predicate?: (element: T, index: number) => boolean, defaultValue?: T): T | undefined; + singleOrDefault(predicate: (element: T, index: number) => element is TOther, defaultValue: TDefault): TOther | TDefault; + singleOrDefault(predicate: (element: T, index: number) => boolean, defaultValue: TDefault): T | TDefault; + singleOrDefault(predicate: (element: T, index: number) => element is TOther): TOther | undefined; + singleOrDefault(predicate: (element: T, index: number) => boolean): T | undefined; + singleOrDefault(defaultValue: TDefault): T | TDefault; + singleOrDefault(): T | undefined; skip(count: number): IEnumerable; skipWhile(predicate: (element: T, index: number) => boolean): IEnumerable; take(count: number): IEnumerable;