Skip to content

Commit

Permalink
adding IxJS augmentation to fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Pat Sissons committed Aug 2, 2017
1 parent 0803cc3 commit ce13702
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion src/types/augmentations.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,34 @@
// tslint:disable:no-unused-variable

// currently there are no augmenatations
import { Enumerable, OrderedEnumerable, Comparer } from 'ix';

// we want to reuse the createOrderedEnumerable that comes with OrderedEnumerable
interface OrderedEnumerablePrototype<T> extends OrderedEnumerable<T> {
createOrderedEnumerable<TKey>(keySelector: (item: T) => TKey, comparer: Comparer<TKey, TKey> | undefined, descending: boolean): OrderedEnumerable<T>;
}

// reach in and grab the OrderedEnumerable prototype by creating an ordered enumerable
const orderedEnumerablePrototype: OrderedEnumerablePrototype<any> = (<any>Enumerable)
.empty()
.orderBy(undefined)
.__proto__
.constructor
.prototype;

function thenBy<T, TKey>(
this: OrderedEnumerablePrototype<T>,
keySelector: (item: T) => TKey,
comparer?: Comparer<TKey, TKey>,
) {
return this.createOrderedEnumerable(keySelector, comparer, false);
}
orderedEnumerablePrototype.thenBy = thenBy;

function thenByDescending<T, TKey>(
this: OrderedEnumerablePrototype<T>,
keySelector: (item: T) => TKey,
comparer?: Comparer<TKey, TKey>,
) {
return this.createOrderedEnumerable(keySelector, comparer, true);
}
orderedEnumerablePrototype.thenByDescending = thenByDescending;

0 comments on commit ce13702

Please sign in to comment.